Python jenkinsapi忽略证书

时间:2017-01-17 15:46:41

标签: python jenkins-api

最近,我把詹金斯变成了https。 这是我使用jenkinsapi的代码:

import jenkinsapi
from jenkinsapi.jenkins import Jenkins
from jenkinsapi.utils.requester import Requester
import requests
url = 'https://jenkinsd:443'
username = 'MyUser'
password = '123'
requests.packages.urllib3.disable_warnings()
jenkins = Jenkins(url, username, password)
jobs = jenkins.get_jobs()
for jobName in jobs:
    print(jobName)

我收到此错误:

requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

我试过了:

jenkins = Jenkins(url, requester=Requester(username, password, baseurl=url, ssl_verify=False))

OR:

jenkins = jenkinsapi.jenkins.Jenkins(url, username, password, requester =Requester(username, password, ssl_verify=False))

我收到此错误:

File "D:\Python34\lib\site-packages\requests-2.7.0-py3.4.egg\requests\adapters.py", line 415, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionRefusedError(10061, 'No connection could be made because the target machine actively refused it', None, 10061, None))

建议请:)

2 个答案:

答案 0 :(得分:4)

解决..

jenkins = Jenkins(网址,用户名,密码,ssl_verify = False)

更正网址后:管理Jenkins>配置系统>詹金斯网址

jenkinsapi现在有效。

https://github.com/pycontribs/jenkinsapi/blob/master/doc/source/ssl_certificate_verification

谢谢!

答案 1 :(得分:-1)

作者似乎包含了一个环境变量来禁用 SSL 验证。这种方法还具有抑制 urllib3 将打印的不安全请求警告的好处。 在执行 python 脚本之前,只需在 shell 中设置下面的变量。

在 Bash 中:

export PYTHONHTTPSVERIFY=0
python myscript.py