Python调用JIRA API遇SSL证书验证失败错误的解决咨询
解决Python调用JIRA API时的SSL证书验证错误
调用JIRA API时遇到SSL证书验证失败错误,错误信息如下:
requests.exceptions.SSLError: HTTPSConnectionPool(host='jira.companyurl.com', port=443): Max retries exceeded with url: /rest/api/2/serverInfo (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
代码示例:
def oauth(): key_cert_data = None with open('/scripts/jira_privatekey.pem', 'r') as key_cert_file: key_cert_data = key_cert_file.read() oauth_dict = { 'access_token': 'XXXXXX', 'access_token_secret': 'YYYYYY', 'consumer_key': 'OauthKey', 'key_cert': key_cert_data } return oauth_dict url = 'https://jira.companyurl.com' jira = JIRA(url, oauth=oauth())
解决方法
1. 指定信任的CA证书(推荐,安全)
若JIRA服务器使用内部CA签发的证书,将CA证书文件路径传入verify参数即可:
# 替换为实际CA证书路径 jira = JIRA(url, oauth=oauth(), verify='/path/to/company_ca.crt')
2. 临时禁用证书验证(仅测试环境使用,不安全)
仅用于临时测试场景,跳过证书验证会带来安全风险:
jira = JIRA(url, oauth=oauth(), verify=False)
3. 更新证书信任池
若证书合法但未被Python信任,可更新Python默认使用的certifi证书包:
pip install --upgrade certifi
也可将JIRA服务器证书添加到系统级受信任证书存储中。
内容的提问来源于stack exchange,提问作者vvazza
相关产品推荐
相关产品推荐

