skip to Main Content

I have been using the Python Jenkins APIs to manager my Jenkins jobs. It has worked for a long time, but it stopped suddenly working. This is the code excerpt:

import jenkins

server = jenkins.Jenkins('https://jenkins.company.com', username='xxxx', password='password')
server._session.verify = False
print(server.jobs_count())

The traceback:

File "", line 1, in
server.jobs_count()

File "E:anaconda3Libsite-packagesjenkins_init_.py", line
1160, in jobs_count
return len(self.get_all_jobs())

File "E:anaconda3Libsite-packagesjenkins_init_.py", line
1020, in get_all_jobs
jobs = [(0, [], self.get_info(query=jobs_query)[‘jobs’])]

File "E:anaconda3Libsite-packagesjenkins_init_.py", line 769,
in get_info
requests.Request(‘GET’, self._build_url(url))

File "E:anaconda3Libsite-packagesjenkins_init_.py", line 557,
in jenkins_open
return self.jenkins_request(req, add_crumb, resolve_auth).text

File "E:anaconda3Libsite-packagesjenkins_init_.py", line 573,
in jenkins_request
self.maybe_add_crumb(req)

File "E:anaconda3Libsite-packagesjenkins_init_.py", line 371,
in maybe_add_crumb
‘GET’, self._build_url(CRUMB_URL)), add_crumb=False)

File "E:anaconda3Libsite-packagesjenkins_init_.py", line 557,
in jenkins_open
return self.jenkins_request(req, add_crumb, resolve_auth).text

File "E:anaconda3Libsite-packagesjenkins_init_.py", line 576,
in jenkins_request
self._request(req))

File "E:anaconda3Libsite-packagesjenkins_init_.py", line 550,
in _request
return self._session.send(r, **_settings)

File "E:anaconda3Libsite-packagesrequestssessions.py", line
622, in send
r = adapter.send(request, **kwargs)

File "E:anaconda3Libsite-packagesrequestsadapters.py", line
507, in send
raise ProxyError(e, request=request)

ProxyError: HTTPSConnectionPool(host=’jenkins.company.com’, port=443): Max
retries exceeded with url:
/job/scp/job/sm/job/9218/job/4198/job/SIT/crumbIssuer/api/json (Caused
by ProxyError(‘Cannot connect to proxy.’, OSError(‘Tunnel connection
failed: 403 Forbidden’)))

Note that there isn’t any proxy on the Jenkins server, and I can use the user/password logon to the Jenkins server without any issues.

I have the crum id and API token, but I haven’t found anything that is indicating how to add the crum into the Python-Jenkins API.

2

Answers


  1. tl;dr: You lack connectivity.

    The jenkins library depends on import requests,
    which is reporting the connectivity error.
    Regrettably, it uses ProxyError in the diagnostic.
    The rationale goes like this:

    • We’re making a GET request for the application.
    • Optionally the "GET from server S" will be turned into "GET from proxy P" if proxying is in use.
    • Eventually we try to contact some host, S or P. Might as well tell a proxy user that state of S is unknown, but state of P is "down".

    Here ends the "why mention proxying?" diagnostic rant.

    When you say "I’m not using proxying", I believe you.
    The diagnostic can be a bit of a red herring for
    folks who are not yet familiar with it.


    When I probe ebs.usps.gov (56.207.107.97) on ports 443, 80, or with ICMP, I see zero response packets.
    You’re in a different part of the net, with different
    filters between you and server, so your mileage might vary.
    I wouldn’t describe that host as a "public server",
    since it offers me no responses.


    It appears you sent SYN to tcp port 443,
    and either some network device discarded that packet,
    or the server replied with SYN-ACK and that
    reply packet was discarded.

    Most likely the server is down or your request was discarded.

    Login or Signup to reply.
  2. The final part of the traceback says:

    ProxyError: HTTPSConnectionPool(host='ebs.usps.gov', port=443)
    

    Which most likely indicates that you have proxy settings that your Python code inherits from somewhere when it runs. It could be environment variables ((HTTP|HTTPS)_PROXY) on POSIX sort of platforms or something similar… If you need to to use a proxy to reach the Jenkins instance, then the issue is in the proxy itself. It blocks your access for some reason. If you do not need to use a proxy, then you should remove the settings affecting your Python code when you run it.

    Also, see what J_H said

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search