Lafada Lafada - 18 days ago 11
reST (reStructuredText) Question

Get jenkins.BadHTTPException when try to get version info from jenkins run on docker

I installed docker container for Jenkins ver. 2.19.1.

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f03c10935bb3 jenkins "/bin/tini -- /usr/lo" 29 hours ago Up 3 hours 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp cocky_colden


Installed
python-jenkins
module to access jenkins server.

I tried first code sample given in docs.

import jenkins

server = jenkins.Jenkins('http://localhost:8080', username='admin', password='mytoken')
user = server.get_whoami()
version = server.get_version()
print('Hello %s from Jenkins %s' % (user['fullName'], version))


But it gives error.

python /tmp/test.py
Traceback (most recent call last):
File "/tmp/test.py", line 5, in <module>
version = server.get_version()
File "/usr/lib/python2.7/site-packages/jenkins/__init__.py", line 616, in get_version
% self.server)
jenkins.BadHTTPException: Error communicating with server[http://localhost:8080/]


I check the docs which mentioned:


From Jenkins vesion 1.426 onward you can specify an API token instead of your real password while authenticating the user against the Jenkins instance.


I used password instead of
token
but get same error.

I tried
curl


curl -X POST http://localhost:8080/job/testjob/build \
> --data token=mytoken \
> --data-urlencode json='{"parameter": [{"name":"id", "value":"123"}, {"name":"verbosity", "value":"high"}]}'
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 403 No valid crumb was included in the request</title>
</head>
<body><h2>HTTP ERROR 403</h2>
<p>Problem accessing /job/testjob/build. Reason:
<pre> No valid crumb was included in the request</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

</body>
</html>


I get token from Name-> Configure -> Show API Token...

Is there anything else I have to enable from jenkins side to access? means, API will get access to this server?

Answer

Try checking the Jenkins security settings - those turned out to be the problem in my case.