【发布时间】:2016-01-07 16:32:15
【问题描述】:
我有一个 python 脚本,我在其中调用 JIRA API 并从 JIRA 获取一些内容,我想将其写入文件。
cmd中的这个命令可以正常工作
curl -D- -u username:password -X GET --data @file.json -H "Content-Type: application/json" http:URL >> output.json
但是,当我尝试在 Python 中执行相同操作时,它并没有写入我的文件(直接指向我的“出现问题”)
#Runs curl script to get component
def write():
name = 'output.json'
try:
file= open(name, 'w')
file.write(subprocess.call('curl -D- -u username:password -X GET --data @file.json -H "Content-Type: application/json" http:URL'))
file.close()
except:
print('something is wrong')
sys.exit(0)
write()
我还尝试让它在下面写一个变量的内容。
curler = (subprocess.call('curl -D- -u username:password -X GET --data @file.json -H "Content-Type: application/json" http:URL'))
def write():
name = 'output.json'
try:
file = open(name, 'w')
file.write(curler)
file.close()
except:
print('something is wrong')
sys.exit(0)
write()
我使用的是 Windows 7 和 Python 3
【问题讨论】:
-
你真的需要做一个shell命令吗,你可以使用
pycurl或requests直接在python中调用而不用shell,这样处理返回的数据就容易多了。 -
您能否向我们展示 Traceback 以便我们查看实际错误?
-
我将尝试使用“请求”,如果我能做出任何事情,我会在这里发帖。目前我试图弄清楚如何在我的 CURL 命令中完全像我想要的那样传递请求。谢谢!
标签: python windows python-3.x command jira