Python无法通过以下方式连接Jira API [英] Python Can't connect Jira API via

查看:452
本文介绍了Python无法通过以下方式连接Jira API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过python(3.6)连接jira的API,但我不断收到错误消息:

I'm trying to connect jira's API via python (3.6) and i keep getting error message:

警告:root:HTTPSConnectionPool(host ='jira',port = 443):URL超过最大重试次数:/secure/rest/api/2/serverInfo/rest/api/2/serverInfo(由SSLError(SSLError引起) (不正确的握手:错误([(('SSL例程','tls_process_server_certificate','证书验证失败')],),))))"在执行GET https://jira/secure/rest/api/2/serverInfo/rest/api/2/serverInfo [{'params':None,'headers':{'User-Agent':'python-requests/2.20.1','Accept-Encoding':'gzip,deflate ','Accept':'application/json,.; q = 0.9','Connection':'keep-alive','Cache-Control':'no-cache','Content-类型':'application/json','X-Atlassian-Token':'no-check'}}] 警告:root:Got ConnectionError [HTTPSConnectionPool(host ='jira',port = 443):URL超过最大重试次数:/secure/rest/api/2/serverInfo/rest/api/2/serverInfo(由SSLError(SSLError引起) (错误的握手:错误([(('SSL例程','tls_process_server_certificate','证书验证失败')],),))))] errno:GET https://jira/secure/rest上没有/api/2/serverInfo/rest/api/2/serverInfo {响应":无,请求":< PreparedRequest [GET]>}}响应":无,请求":< PreparedRequest [GET]>} 警告:root:从GET https://jira/secure/rest/api/2/serverInfo/rest/api/2/serverInfo中得到可恢复的错误,将在7.466325591185807s中重试[1/3].错误:HTTPSConnectionPool(host ='jira',端口= 443):网址超过了最大重试次数:/secure/rest/api/2/serverInfo/rest/api/2/serverInfo(由SSLError(SSLError("bad handshake"造成的错误握手引起) :错误([(('SSL例程','tls_process_server_certificate','证书验证失败')],)'',),))

WARNING:root:HTTPSConnectionPool(host='jira', port=443): Max retries exceeded with url: /secure/rest/api/2/serverInfo/rest/api/2/serverInfo (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)) while doing GET https://jira/secure/rest/api/2/serverInfo/rest/api/2/serverInfo [{'params': None, 'headers': {'User-Agent': 'python-requests/2.20.1', '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'}}] WARNING:root:Got ConnectionError [HTTPSConnectionPool(host='jira', port=443): Max retries exceeded with url: /secure/rest/api/2/serverInfo/rest/api/2/serverInfo (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))] errno:None on GET https://jira/secure/rest/api/2/serverInfo/rest/api/2/serverInfo {'response': None, 'request': <PreparedRequest [GET]>}{'response': None, 'request': <PreparedRequest [GET]>} WARNING:root:Got recoverable error from GET https://jira/secure/rest/api/2/serverInfo/rest/api/2/serverInfo, will retry [1/3] in 7.466325591185807s. Err: HTTPSConnectionPool(host='jira', port=443): Max retries exceeded with url: /secure/rest/api/2/serverInfo/rest/api/2/serverInfo (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

这是我的代码:

un='myusername'
pwd='mypassword'
server='https://jira/xxxx'

jira = jira = JIRA(basic_auth=(un, pwd), options={'server': server})
issue = jira.issue('some issue name')

print(issue.fields.project.key)
print(issue.fields.issuetype.name) 

在同一台服务器上使用curl时,一切正常.

When using curl to the same server everything works good.

推荐答案

您可以为verify选项提供必要的证书.

You can provide the necessary certificate to the verify option.

jira-pythonRequests用于HTTP (文档).

根据请求文档 您可以在verify中指定证书文件的路径. 因此,您可以像这样在verify中提供根证书:

According to Requests documentation you can specify a path to a certificate file in verify. So you can provide the root certificate in verify like so:

jira_options = {
   'server': jira_server_name,
   'verify': 'path/to/root/certificate',
}

因此,在您的情况下,请更改为:

So in your case just change to this:

jira = jira = JIRA(basic_auth=(un, pwd), options={'server': server,'verify': 'path/to/root/certificate',})

例如,在Chrome中,您可以显示此

In Chrome for example you can show the certificate as described in this article

在Chrome中连接到服务器,然后单击地址栏左上角显示的锁,然后右键单击该锁(请参见下图),然后单击详细信息",然后单击查看证书".然后将此证书保存到文件中,并在verify中进行引用.

Connect to your server in Chrome and click on the lock shown in the left-hand corner of address bar and right-click that lock (see image below), then click 'details', then 'view certificate'. Then save this cert to file and refer to it in verify.

另一种方法(如下面的评论中的@Snow所述)是通过F12打开开发工具,然后导航到安全性"选项卡.

Another way, as @Snow mentioned in the comments below, is to open the development-tools via F12 and then navigate to the Security tab.

从文档中

SSL CERT验证:

如果将verify设置为目录的路径,则必须已使用OpenSSL随附的c_rehash实用程序处理了该目录.

If verify is set to a path to a directory, the directory must have been processed using the c_rehash utility supplied with OpenSSL.

客户端证书:

本地证书的私钥必须未加密.当前,请求"不支持使用加密密钥.

The private key to your local certificate must be unencrypted. Currently, Requests does not support using encrypted keys.

还有设置'verify':false的选项-不建议您这样做,因为关闭证书验证会使您容易受到

There's also the option to set 'verify':false - thou it's not recommended since turning off certificate verification leaves you vulnerable for Man-in-the-Middle attacks.

这篇关于Python无法通过以下方式连接Jira API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆