如何使用python3访问JIRA-REST API修复证书问题?

时间:2017-01-13 08:41:50

标签: python json curl jira python-jira

在Redhat框上(红帽企业Linux工作站版本6.8(圣地亚哥))我能够向JIRA实例发出curl请求,如下所示:

curl -k -D- -u "user":"password" -X GET -H "Content-Type: application/json" https://some_url/jira/rest/api/2/search?jql=assignee=fritz

此请求返回一个有效的json,其中包含实际数据。到现在为止还挺好。

要访问和评估来自json的信息,我尝试使用jira-python来为jira json设置解析器。代码如下:

jira = JIRA('https://some_url/jira', basic_auth=('user','password'))

导致如下错误:

WARNING:root:[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) while doing GET https://some_url/jira/rest/api/2/serverInfo [{'params': None, 'headers': {'User-Agent': 'python-requests/2.12.4', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json,*.*;q=0.9', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json', 'X-Atlassian-Token': 'no-check'}}]

为什么在尝试使用python访问JIRA时出现证书错误,但是在使用curl时我不知道?以及如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

如果要跳过证书验证(不安全),请将verify设置为False。

jira = JIRA('https://some_url/jira', verify=False, basic_auth=('user','password'))

正如@frlan指出的那样,最好验证证书。只需浏览JIRA参数,并指定您的客户端证书进行验证。

<强>说明: https://github.com/pycontribs/jira/blob/5cade37e56612caee36db6310b6e0ef935726944/jira/client.py

 * verify -- Verify SSL certs. Defaults to ``True``.