I am trying to use either this library or python-jenkins, but have failed to connect to a Jenkins server that requires authentication. Without authentication, everything works well.
Supposing my username is "kenn" and my password is "foobar" and my Jenkins server is at "https://jenkins.example.com"
wget --auth-no-challenge --http-user=kenn --http-password=foobar https://jenkins.example.com/api/python
I have also used python-jenkins and confirmed that works. But this does not:
It results in the following output, where I have turned on logging in ipython and added the password to the debug message. I have confirmed that when the password is wrong it also has this output.
DEBUG:jenkinsapi.jenkins:args: ['kenn', 'foobar', 'https://jenkins.example.com/', None, None, None, None]
DEBUG:jenkinsapi.utils.urlopener:Adding BasicAuthHandler: url:https://jenkins.example.com/, user:kenn, pass:foobar
WARNING:jenkinsapi.jenkinsbase:Error reading https://jenkins.example.com/api/python/
ERROR:jenkinsapi.jenkinsbase:HTTP Error 403: Forbidden
Traceback (most recent call last):
File "/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.py", line 67, in get_data
stream = fn_urlopen(url)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 400, in open
response = meth(req, response)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 438, in error
return self._call_chain(*args)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 372, in _call_chain
result = func(*args)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 521, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
ERROR:jenkinsapi.utils.retry:HTTP Error 403: Forbidden
Traceback (most recent call last):
File "/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/utils/retry.py", line 24, in retry_function
result = fn( *args, **kwargs )
File "/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.py", line 67, in get_data
stream = fn_urlopen(url)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 400, in open
response = meth(req, response)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 438, in error
return self._call_chain(*args)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 372, in _call_chain
result = func(*args)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/urllib2.py", line 521, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
WARNING:jenkinsapi.utils.retry:get_data failed at attempt 1, trying again.
ERROR:jenkinsapi.jenkinsbase:HTTP Error 403: Forbidden
Traceback (most recent call last):
File "/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.py", line 33, in __init__
self.poll()
File "/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.py", line 40, in poll
self._data = self._poll()
File "/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.py", line 44, in _poll
return retry_function(self.RETRY_ATTEMPTS , self.get_data, url)
File "/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/utils/retry.py", line 39, in retry_function
raise e
HTTPError: HTTP Error 403: Forbidden
WARNING:jenkinsapi.jenkinsbase:Failed to conenct to https://jenkins.example.com/
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (59, 0))
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
~/dev/jenkinsapi-work/<ipython-input-7-c15028c8268e> in <module>()
----> 1 j = jenkins.Jenkins('https://jenkins.example.com/', username = 'kenn', password = 'foobar')
/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkins.pyc in __init__(self, baseurl, username, password, proxyhost, proxyport, proxyuser, proxypass)
39 self.proxyuser = proxyuser
40 self.proxypass = proxypass
---> 41 JenkinsBase.__init__(self, baseurl)
42
43 def get_proxy_auth(self):
/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.pyc in __init__(self, baseurl, poll)
31 if poll:
32 try:
---> 33 self.poll()
34 except urllib2.HTTPError, hte:
35 log.exception(hte)
/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.pyc in poll(self)
38
39 def poll(self):
---> 40 self._data = self._poll()
41
42 def _poll(self):
/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.pyc in _poll(self)
42 def _poll(self):
43 url = self.python_api_url(self.baseurl)
---> 44 return retry_function(self.RETRY_ATTEMPTS , self.get_data, url)
45
46 def get_jenkins_obj(self):
/Users/kenn/.virtualenvs/jenkinsapi-work/lib/python2.7/site-packages/jenkinsapi/utils/retry.pyc in retry_function(tries, fn, *args, **kwargs)
37 log.warn( "%s failed at attempt %i, trying again." % ( fn_name , attemptno ) )
38 time.sleep( DEFAULT_SLEEP_TIME )
---> 39 raise e
HTTPError: HTTP Error 403: Forbidden
I have confirmed that if I just put a totally random password in, I get the same result.