-
Notifications
You must be signed in to change notification settings - Fork 676
Closed
Labels
Description
It's now impossible to connect to GitLab unless http_username and http_password are explicitly set, even when using token authentication.
This may be a result of a change in the requests Python package, but I'm not sure.
Workaround
A workaround is to set the username and password values to an empty string instead of leaving them unspecified, which results in a value of None internally.
- From a Python program using the library directly, pass
http_username=""andhttp_password=""to the Gitlab class constructor. - From the command-line interface where a
.iniconfig file contains the server URL and authentication token, add two lines to the server configuration section:
http_username=
http_password=
Problematic behavior
With a configuration file guest.ini that has url and private_token defined, but does not have both http_username and http_password, it now fails with an error caused by an exception. This used to work fine.
gitlab-script.py -c guest.ini current-user get
Can't connect to GitLab server (sequence item 0: expected a bytes-like object, NoneType found)
The detailed traceback looks like this:
Traceback (most recent call last):
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\gitlab\__init__.py", line 357, in _raw_get
self.http_password))
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\requests\sessions.py", line 501, in get
return self.request('GET', url, **kwargs)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\requests\sessions.py", line 474, in request
prep = self.prepare_request(req)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\requests\sessions.py", line 407, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\requests\models.py", line 306, in prepare
self.prepare_auth(auth, url)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\requests\models.py", line 527, in prepare_auth
r = auth(self)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\requests\auth.py", line 68, in __call__
r.headers['Authorization'] = _basic_auth_str(self.username, self.password)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\requests\auth.py", line 38, in _basic_auth_str
b64encode(b':'.join((username, password))).strip()
TypeError: sequence item 0: expected a bytes-like object, NoneType found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Temp\shiningpanda3710795791656575820.py", line 7, in <module>
p = gl.projects.get(os.environ["GITLAB_PROJECT_PATH"])
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\gitlab\objects.py", line 102, in get
return self.obj_cls.get(self.gitlab, id, **args)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\gitlab\objects.py", line 274, in get
return cls(gl, id, **kwargs)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\gitlab\objects.py", line 377, in __init__
data = self.gitlab.get(self.__class__, data, **kwargs)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\gitlab\__init__.py", line 497, in get
r = self._raw_get(url, **kwargs)
File "C:\Jenkins\Home\shiningpanda\jobs\920fc076\virtualenvs\d0498fac\lib\site-packages\gitlab\__init__.py", line 360, in _raw_get
"Can't connect to GitLab server (%s)" % e)
gitlab.exceptions.GitlabConnectionError: Can't connect to GitLab server (sequence item 0: expected a bytes-like object, NoneType found)
Environment
Python 3.5.2 on Windows.
Python package versions installed include:
$ pip list
oauthlib (2.0.1)
pip (9.0.1)
python-dateutil (2.5.3)
python-gitlab (0.16)
requests (2.12.2)
requests-oauthlib (0.7.0)
requests-toolbelt (0.7.0)
setuptools (20.10.1)
six (1.10.0)
tlslite (0.4.9)
Reactions are currently unavailable