python-jenkins-developers team mailing list archive
-
python-jenkins-developers team
-
Mailing list archive
-
Message #00239
[Bug 1501441] Re: Unwanted [forward] slash in get_info results 404 error in case server url looks like "http://domainname[:port]/myjenkins"
** Changed in: python-jenkins
Assignee: Anton Haldin (anton-haldin) => (unassigned)
--
You received this bug notification because you are a member of Python
Jenkins Developers, which is subscribed to Python Jenkins.
https://bugs.launchpad.net/bugs/1501441
Title:
Unwanted [forward] slash in get_info results 404 error in case server
url looks like "http://domainname[:port]/myjenkins"
Status in Python Jenkins:
Confirmed
Bug description:
Function get_info with default value of parameter item uses wrong url
to send request to Jenkins server in case server url looks like
"http://domainname[:port]/myjenkins"
source code of python-jenkins/jenkins/__init__.py:
437 def get_info(self, item="", query=None):
.....
.....
456 url = "/".join((item, INFO))
457 if query:
458 url += query
459 try:
460 return json.loads(self.jenkins_open(
461 Request(self._build_url(url))
with INFO='api/json' and item="" works like this:
>>> item = ""
>>> url = "/".join((item, 'api/json'))
>>> print url
/api/json
As a result function _build_url produces wrong url with self.server="http://192.168.0.23:8081/jenkins/" and query="?tree=jobs[url,color,name,jobs]":
>>> from six.moves.urllib.parse import quote, urlencode, urljoin, urlparse
>>> urljoin(self.server, "/api/json?tree=jobs[url,color,name,jobs]")
'http://192.168.0.23:8081/api/json?tree=jobs[url,color,name,jobs]'
>>> print self.server
http://192.168.0.23:8081/jenkins/
>>> urljoin(self.server, "api/json?tree=jobs[url,color,name,jobs]")
'http://192.168.0.23:8081/jenkins/api/json?tree=jobs[url,color,name,jobs]'
Functions get_jobs and get_all_jobs are affected by this issue.
>>>import jenkins
>>>server = jenkins.Jenkins('http://xx.xx.0.23:8081/jenkins/', username='jenkins', password='jenkins')
>>>version = server.get_version()
>>> print version
1.565.3
>>> jobs = server.get_jobs()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/jenkins/__init__.py", line 625, in get_jobs
return self.get_all_jobs(folder_depth=folder_depth)
File "/usr/local/lib/python2.7/site-packages/jenkins/__init__.py", line 674, in get_all_jobs
jobs = [(0, "", self.get_info(query=JOBS_QUERY)['jobs'])]
File "/usr/local/lib/python2.7/site-packages/jenkins/__init__.py", line 461, in get_info
Request(self._build_url(url))
File "/usr/local/lib/python2.7/site-packages/jenkins/__init__.py", line 361, in jenkins_open
raise NotFoundException('Requested item could not be found')
jenkins.NotFoundException: Requested item could not be found
>>> info = server.get_info(query="?tree=jobs[url,color,name,jobs]")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/jenkins/__init__.py", line 461, in get_info
Request(self._build_url(url))
File "/usr/local/lib/python2.7/site-packages/jenkins/__init__.py", line 361, in jenkins_open
raise NotFoundException('Requested item could not be found')
jenkins.NotFoundException: Requested item could not be found
Jenkins is accessible by using "http://192.168.0.23:8081/jenkins/" url and credentials "jenkins/jenkins"
As I can see in access logs the 404 code was returned because of wrong address in request :
xx.xx.0.24 - - [29/Sep/2015:17:58:00 +0000] "GET /api/json?tree=jobs[url,color,name,jobs] HTTP/1.1" 404 967
xx.xx.0.24 - - [29/Sep/2015:18:05:33 +0000] "GET /api/json?tree=jobs[url,color,name,jobs] HTTP/1.1" 404 967
It should send request to "GET
/jenkins/api/json?tree=jobs[url,color,name,jobs]" but it sends "GET
/api/json?tree=jobs[url,color,name,jobs]"
Jenkins is working properly. It was checked by wget --auth-no-challenge --http-user=jenkins --http-password=jenkins http://192.168.0.23:8081/jenkins/api/json?tree=jobs[url,color,name,jobs]
Record from access log:
xx.xx.0.24 - - [29/Sep/2015:18:06:09 +0000] "GET /jenkins/api/json?tree=jobs[url,color,name,jobs] HTTP/1.0" 200 188
I've tested fix and would like to push it back to project:
-bash-4.1$ git diff
diff --git a/jenkins/__init__.py b/jenkins/__init__.py
index ca46fd7..4677bdb 100644
--- a/jenkins/__init__.py
+++ b/jenkins/__init__.py
@@ -453,7 +453,10 @@ class Jenkins(object):
u'name': u'my_job'}
"""
- url = "/".join((item, INFO))
+ if item != '':
+ url = "/".join((item, INFO))
+ else:
+ url = INFO
if query:
url += query
try:
This fix should not broke functionality "Adds Cloudbees folder plugin
support" https://github.com/stackforge/python-
jenkins/commit/7267eec4542696b48fea6a07ccdf34c6e887f75f
Project "openstack-infra/jenkins-job-builder" is affected by this
issue.
To manage notifications about this bug go to:
https://bugs.launchpad.net/python-jenkins/+bug/1501441/+subscriptions
References