Activity log for bug #1799107

Date Who What changed Old value New value Message
2018-10-22 02:25:56 Yen-wei Liu bug added bug
2018-10-22 02:29:45 Yen-wei Liu 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-jenkins: 1.3.0 Python: 3.5.2 (stock) Thanks for your attention. ywliu 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