1

I try to update Jenkins jobs' config programmatically, and the python Jenkins api looked ok, but I can't retrieve a config because of HTTP error 403 (forbidden):

from jenkinsapi import api
j = api.Jenkins('https://server.test.com/hudson', 'fp12210', 'xxxxxxxx')
job = j.get_job('BBB-100-CheckStatusAll')
conf = job.get_config()

Traceback (most recent call last):
  ...
  File "C:\Python27\lib\urllib2.py", line 521, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden

Adding user and password in URL, as mentionned in another SO post, fails too:

 j = api.Jenkins('https://fp12210:xxxxxxxx@server.test.com/hudson')

Traceback (most recent call last):
  ...
  File "build\bdist.win32\egg\jenkinsapi\utils\retry.py", line 39, in retry_function
    raise e
InvalidURL: nonnumeric port: 'xxxxxxxx@server.test.com/hudson'

Do you have any idea ?

Community
  • 1
  • 1
Emmanuel
  • 13,935
  • 12
  • 50
  • 72
  • Have you tried accessing the web api directly? Something like `curl -u "fp12210:xxxxx" https://server.test.com/hudson/job/BBB-100-CheckStatusAll/config.xml`. Maybe the problem isn't on the python side of things. – gvalkov Sep 17 '12 at 16:45
  • Well the second method isn't going to work because the library needs to handle that format of URL correctly. For example, browsers 64 encode the username and password and stick them in as headers before sending the actual request. It looks like the Jenkins api library you're using doesn't do that and instead includes them in the url :( – systemizer Sep 17 '12 at 17:29
  • see http://stackoverflow.com/a/24048578/1733117 – dnozay Jun 04 '14 at 22:47

2 Answers2

0

This SO post is the solution. I now get an error 500, but this is another story...

Community
  • 1
  • 1
Emmanuel
  • 13,935
  • 12
  • 50
  • 72
0

The python jenkins api uses urllib2.

You can see this answer: https://stackoverflow.com/a/24048578/1733117 for using preemptive basic authentication, or retry with basic authentication when you get a 403 (e.g. anonymous user has limited access).

Community
  • 1
  • 1
dnozay
  • 23,846
  • 6
  • 82
  • 104