8

Recently, I turned jenkins to https. This is my code to use 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)

I get this error:

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

I tried:

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))

I get this error:

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))

Advice please :)

Yehiel G
  • 231
  • 1
  • 2
  • 8

2 Answers2

14

Solved..

jenkins = Jenkins(url, username, password, ssl_verify=False)

After correcting url : Manage Jenkins > Configure system > Jenkins URL

The jenkinsapi now works.

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

Thanks!

Yehiel G
  • 231
  • 1
  • 2
  • 8
  • 11
    For those who don't have `ssl_verify` in the `__init__` method of Jenkins, just set `jenkins = Jenkins(url, username, password); jenkins._session.verify = False`. – Berci Jan 29 '19 at 12:23
0

It appears the authors included an environment variable to disable SSL verification. This approach also has the benefit of suppressing the insecure request warnings that urllib3 will print. Simply set the variable below in your shell before executing your python script.

In Bash:

export PYTHONHTTPSVERIFY=0
python myscript.py
Dan
  • 11