Jenkins Job Builder failing authentication with Jenkins due to encoding issue?

1.5k Views Asked by At

I'm trying to run jenkins-jobs update for the first time on my system, but it fails on authentication.

Command:

jenkins-jobs --conf ./jjb.ini update jobs/

Where jobs contains a test.yml - a miniature build project just for testing. jjb.ini is:

[jenkins]
user=admin
password={{ admin_api_token }} # Inserted API token here.
url=http://127.0.0.1:8080
query_plugins_info=False

Expected result:

Success, and import of the example build project into Jenkins.

Actual result:

INFO:jenkins_jobs.cli.subcommand.update:Updating jobs in ['jobs/'] ([])
INFO:jenkins_jobs.builder:Number of jobs generated:  1
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 557, in jenkins_request
    self._request(req))
  File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 508, in _response_handler
    response.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 840, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Invalid password/token for user: b'admin' for url: http://127.0.0.1:8080/crumbIssuer/api/json

What catches my eye here is that the authentication fails for b'admin, not for admin. This is also reflected in the "People" page on Jenkins web-interface, which before the attempted login only showed admin, but after the attempted login shows:

enter image description here

From what I've been able to figure out, there may be a problem with encoding in the login request from JJB, but I'm looking for help when it comes to how to go about trying to fix this.

Current setup:

Ubuntu 16.04.4 LTS
Jenkins 2.125 (working as expected, at :8080)
jenkins-job-builder 2.0.9 
Python 3.5.2
pip 10.0.1 from /usr/local/lib/python3.5/dist-packages/pip-10.0.1-py3.5.egg/pip (python 3.5)
java -version: openjdk version "1.8.0_171"
2

There are 2 best solutions below

2
On

It works with requests==2.19.1

sudo pip uninstall requests sudo pip install requests $ pip freeze | grep requests requests==2.19.1

1
On

The following steps resolved the issue in my case:

pip3.7 freeze | grep requests 

pip3.7 uninstall requests

pip3.7 install requests

pip3.7 freeze | grep requests