diff --git a/docs/api-usage.rst b/docs/api-usage.rst index 4c4ad19c8..00ebcfff5 100644 --- a/docs/api-usage.rst +++ b/docs/api-usage.rst @@ -25,7 +25,7 @@ To connect to a GitLab server, create a ``gitlab.Gitlab`` object: gl = gitlab.Gitlab('http://10.0.0.1', 'JVNSESs8EwWRx5yDxM5q') # oauth authentication - gl = gitlab.Gitlab('http://10.0.0.1', my_oauth2_token) + gl = gitlab.Gitlab('http://10.0.0.1', oauth_token='my_oauth2_token') # or username/password authentication gl = gitlab.Gitlab('http://10.0.0.1', email='jdoe', password='s3cr3t') diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 1150fd287..29beccecf 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -358,7 +358,7 @@ def set_token(self, token=None, oauth_token=None): if oauth_token: self.headers.pop("PRIVATE-TOKEN", None) - self.headers["Authorization"] = "Bearer: %s" % oauth_token + self.headers["Authorization"] = "Bearer %s" % oauth_token elif token: self.headers.pop("Authorization", None) self.headers["PRIVATE-TOKEN"] = token @@ -397,6 +397,14 @@ def _raw_get(self, path_, content_type=None, streamed=False, **kwargs): url = '%s%s' % (self._url, path_) headers = self._create_headers(content_type) + + if 'Authorization' in self.headers: + auth = None + else: + auth = requests.auth.HTTPBasicAuth( + self.http_username, + self.http_password) + try: return self.session.get(url, params=kwargs, @@ -404,9 +412,7 @@ def _raw_get(self, path_, content_type=None, streamed=False, **kwargs): verify=self.ssl_verify, timeout=self.timeout, stream=streamed, - auth=requests.auth.HTTPBasicAuth( - self.http_username, - self.http_password)) + auth=auth) except Exception as e: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % e) @@ -438,7 +444,7 @@ def _raw_list(self, path_, cls, extra_attrs={}, **kwargs): results = [cls(self, item, **params) for item in r.json() if item is not None] if ('next' in r.links and 'url' in r.links['next'] - and get_all_results is True): + and get_all_results is True): args = kwargs.copy() args['next_url'] = r.links['next']['url'] results.extend(self.list(cls, **args))