【发布时间】:2018-04-02 10:40:58
【问题描述】:
我想将此 BASH 代码转换为 python 脚本:
curl -XN -u user:Pass -X GET -H "Content-Type: application/json" https://jira.company.com/rest/api/2/search?jql=project='"Technology"+AND+summary~"Remove%20User*"+AND+issuetype="Task"+AND+status!="DONE"' | python -m json.tool > /var/lib/rundeck/1.json
到目前为止我有这个
headers = {
'Content-Type': 'application/json',
}
params = (
('jql', 'project="Technology" AND summary~"Remove User*" AND issuetype="Task" AND status!="DONE"'),
)
response = requests.get('https://jira.company.com/rest/api/2/search', headers=headers, params=params, auth=('user', 'Pass'))
print response
作为回复我得到<Response [200]>
如何将此命令的输出打印到 JSON 文件(如在 bash 脚本中)?
使用此代码获取 JSON 文件,但不是 JSON 结构(作为纯文本):
with open('/var/lib/rundeck/1.json', 'w') as outfile:
outfile.write(response.content)
使用了这个转换器:
【问题讨论】:
-
尝试使用第三个库请求:docs.python-requests.org/en/master