Jenkins HTTPS Basic Auth fails with Python 3.5

Bug #1799107 reported by Yen-wei Liu
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Python Jenkins
New
Undecided
Unassigned

Bug Description

Hi,

I tried the example one from the document with python-jenkins 1.3.0 on Ubuntu 16.04.5 x64 with stock Python 3.5.2 with HTTPS and SSL cert verification disabled :

=====
import os
import jenkins
os.environ['PYTHONHTTPSVERIFY'] = "0"

server = jenkins.Jenkins('https://<my jenkins server>:8443/jenkins',
    username='user', password='password')

user = server.get_whoami()
version = server.get_version()

print('Hello %s from Jenkins %s' % (user['fullName'], version))
======

And I got this error:

jenkins.JenkinsException: Error in request. Possibly authentication failed [401]:

After digging into python-jenkins code, I found out this one at line 317 in __init__.py:

=====
if username is not None and password is not None:
    self._auths[0] = (
        'basic',
        requests.auth.HTTPBasicAuth(
            username.encode('utf-8'), password.encode('utf-8'))
    )
=====

the "encode('utf-8')" would make username and password binary strings and in requests.auth:

=====
def _basic_auth_str(username, password):
    """Returns a Basic Auth string."""

    authstr = 'Basic ' + to_native_string(
        b64encode(('%s:%s' % (username, password)).encode('latin1')).strip()
    )

    return authstr
=====
the parameter passed to b64encode() would become "b'user':b'password'" so the authentication would fail.

So far I remove encode('utf-8') in __init__.py so it would work. Just curious: is it my problem or how would this work with encode('utf-8') ?

OS: Ubuntu 16.04.5 X64
Python: 3.5.2 (stock)
Python-jenkins: 1.3.0
requests: 2.9.1

Thanks for your attention.

ywliu

Yen-wei Liu (ywliu)
description: updated
Revision history for this message
Marcospoon (marcospoon) wrote :

Has it ever been resolved somehow? So far this is the only solution I could find.

OS: Windows 10 1809
Python: 3.7.2
Python-jenkins: 1.5.0
Requests: 2.11.1

Revision history for this message
webrat (irc-webratz) wrote :

seein the same problem too

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.