使用Python连接JIRA API时SSL3证书验证失败

2024-05-12 09:39:12 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图使用Python2.7和JIRA REST API(http://jira-python.readthedocs.org/en/latest/)连接到JIRA时,当前遇到了一个错误。

当我执行以下操作时:

from jira.client import JIRA

options = {
    'server': 'https://jira.companyname.com'
}
jira = JIRA(options)

我在控制台中收到以下错误消息:

requests.exceptions.SSLError: [Errno 1] _ssl.c:507: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

有没有什么我可能漏掉了或者做错了?

谢谢!


Tags: fromorgimportclientrestapihttpserver
3条回答

我知道我的回答迟了,但希望这能帮助一些人。


为什么不应关闭验证

虽然关闭证书验证是最简单的“解决方案”,但是 不明智的做法。它本质上说, “不管我信不信你,反正我会把所有的信息都发给你的。” 这会让你成为中间人。

如果你连接到你公司的Jira服务器并且它有一个 TLS/SSL证书,您应该对此进行验证。 我想问问你的IT部门证书在哪里。可能是 在你公司的根证书中。

如果你用Chrome连接到服务器(例如) 如果它是安全的,它应该在地址栏的左角显示一个锁 通过TLS/SSL。

你可以在Chrome中Right-Click that lock -> Details -> View Certificate

好吧,那我该怎么办?

直接向verify选项提供必要的证书。

jira-python使用Requests作为HTTP内容(See documentation)。 根据Requests documentation 可以在verify中指定证书文件的路径。

因此,您可以在verify中为您的公司提供根证书,如下所示:

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

如果你使用的是Windows机器(一个安全的假设?),那个根 证书存储在注册表中,是获取证书的最佳方式 正在使用^{}

我遇到了一个类似的SSL证书验证错误,通过查看“JIRA”方法的定义,它有可能关闭验证。

    :param options: Specify the server and properties this client will use. Use a dict with any
     of the following properties:
      * server -- the server address and context path to use. Defaults to ``http://localhost:2990/jira``.
      * rest_path -- the root REST path to use. Defaults to ``api``, where the JIRA REST resources live.
      * rest_api_version -- the version of the REST resources under rest_path to use. Defaults to ``2``.
      * verify -- Verify SSL certs. Defaults to ``True``.
      * resilient -- If it should just retry recoverable errors. Defaults to `False`.

试试这个:

from jira.client import JIRA

options = {'server': 'https://jira.companyname.com','verify':False}
jira = JIRA(options)

在Windows系统上,请执行以下操作:

  1. 使用谷歌浏览器进入网站,然后点击锁定按钮。
  2. 现在单击“证书”,将弹出一个新窗口。
  3. 下一步单击“Certification Path”(证书路径),从列表中选择第一个将成为根目录的选项,然后选择“View Certificate”(查看证书),将弹出另一个窗口。
  4. 转到“详细信息”选项卡,单击“复制到文件”。然后单击“下一步”,选择“Base-64 encoded x509.(CER)”单选按钮,单击“下一步”,并在本地保存.CER文件。

获取.cer文件后,将其添加到python脚本中,如下所示:

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

这应该可以在没有任何安全警告的情况下工作。

相关问题 更多 >