【问题标题】:Python-Jenkins Tunnel connection failed: 403 ForbiddenPython-Jenkins Tunnel connection failed: 403 Forbidden
【发布时间】:2022-12-02 03:55:01
【问题描述】:

I have been using the Python Jenkins apis to manager my Jeninks jobs. it ahs 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:\anaconda3\Lib\site-packages\jenkins_init_.py", line 1160, in jobs_count return len(self.get_all_jobs())

File "E:\anaconda3\Lib\site-packages\jenkins_init_.py", line 1020, in get_all_jobs jobs = [(0, [], self.get_info(query=jobs_query)['jobs'])]

File "E:\anaconda3\Lib\site-packages\jenkins_init_.py", line 769, in get_info requests.Request('GET', self._build_url(url))

File "E:\anaconda3\Lib\site-packages\jenkins_init_.py", line 557, in jenkins_open return self.jenkins_request(req, add_crumb, resolve_auth).text

File "E:\anaconda3\Lib\site-packages\jenkins_init_.py", line 573, in jenkins_request self.maybe_add_crumb(req)

File "E:\anaconda3\Lib\site-packages\jenkins_init_.py", line 371, in maybe_add_crumb 'GET', self._build_url(CRUMB_URL)), add_crumb=False)

File "E:\anaconda3\Lib\site-packages\jenkins_init_.py", line 557, in jenkins_open return self.jenkins_request(req, add_crumb, resolve_auth).text

File "E:\anaconda3\Lib\site-packages\jenkins_init_.py", line 576, in jenkins_request self._request(req))

File "E:\anaconda3\Lib\site-packages\jenkins_init_.py", line 550, in _request return self._session.send(r, **_settings)

File "E:\anaconda3\Lib\site-packages\requests\sessions.py", line 622, in send r = adapter.send(request, **kwargs)

File "E:\anaconda3\Lib\site-packages\requests\adapters.py", line 507, in send raise ProxyError(e, request=request)

ProxyError: HTTPSConnectionPool(host='ebs.usps.gov', 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 is no proxy on the Jenkins server, and I can use the user/password logon to the Jenkins server with no issues.

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

Appreciate any suggestion

【问题讨论】:

  • Setting verify to False appears to be irrelevant. It's a cert check, and you don't even get far enough in the protocol to learn any server cert details.
  • this is a test, shortest code snip that points to the issue, and generate the exact trace, yes, the cert line has nothing to do with the issue

标签: python json api jenkins


【解决方案1】:

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 proxy to reach the jenkins, then the issue is in proxy itself - it blocks your access for some reason. If you do not need to use proxy, then you should remove the settings effecting your python code when you run it.

Also, see what @J_H said ..

Anyway, the problem

【讨论】:

    【解决方案2】:

    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.

    【讨论】:

      猜你喜欢
      • 2022-12-26
      • 1970-01-01
      • 2017-12-30
      • 2015-12-05
      • 2020-10-13
      • 1970-01-01
      • 2023-04-04
      • 2021-09-14
      • 2015-04-03
      相关资源
      最近更新 更多