Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1da7c53

Browse filesBrowse files
nejchJohnVillalovos
authored andcommitted
docs(advanced): clarify netrc, proxy behavior with requests
1 parent 4afeaff commit 1da7c53
Copy full SHA for 1da7c53

File tree

Expand file treeCollapse file tree

1 file changed

+37
-26
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+37
-26
lines changed
Open diff view settings
Collapse file

‎docs/api-usage-advanced.rst‎

Copy file name to clipboardExpand all lines: docs/api-usage-advanced.rst
+37-26Lines changed: 37 additions & 26 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@ Using a custom session
66
----------------------
77

88
python-gitlab relies on ``requests.Session`` objects to perform all the
9-
HTTP requests to the Gitlab servers.
9+
HTTP requests to the GitLab servers.
1010

11-
You can provide your own ``Session`` object with custom configuration when
12-
you create a ``Gitlab`` object.
11+
You can provide a custom session to create ``gitlab.Gitlab`` objects:
12+
13+
.. code-block:: python
14+
15+
import gitlab
16+
import requests
17+
18+
session = requests.Session()
19+
gl = gitlab.Gitlab(session=session)
20+
21+
# or when instantiating from configuration files
22+
gl = gitlab.Gitlab.from_config('somewhere', ['/tmp/gl.cfg'], session=session)
23+
24+
Reference:
25+
https://requests.readthedocs.io/en/latest/user/advanced/#session-objects
1326

1427
Context manager
1528
---------------
@@ -28,24 +41,34 @@ properly closed when you exit a ``with`` block:
2841
The context manager will also close the custom ``Session`` object you might
2942
have used to build the ``Gitlab`` instance.
3043

31-
Proxy configuration
32-
-------------------
44+
netrc authentication
45+
--------------------
3346

34-
The following sample illustrates how to define a proxy configuration when using
35-
python-gitlab:
47+
python-gitlab reads credentials from ``.netrc`` files via the ``requests`` backend by default,
48+
which may override authentication headers you set on your client.
49+
50+
For more granular control, you can disable this `Using a custom session`_
51+
and explicitly setting ``trust_env=False`` as described in the ``requests`` documentation.
3652

3753
.. code-block:: python
3854
39-
import os
4055
import gitlab
4156
import requests
4257
43-
session = requests.Session()
44-
session.proxies = {
45-
'https': os.environ.get('https_proxy'),
46-
'http': os.environ.get('http_proxy'),
47-
}
48-
gl = gitlab.Gitlab(url, token, api_version=4, session=session)
58+
session = requests.Session(trust_env=False)
59+
gl = gitlab.Gitlab(session=session)
60+
61+
Reference:
62+
https://requests.readthedocs.io/en/latest/user/authentication/#netrc-authentication
63+
64+
Proxy configuration
65+
-------------------
66+
67+
python-gitlab accepts the standard ``http_proxy``, ``https_proxy`` and ``no_proxy``
68+
environment variables via the ``requests`` backend. Uppercase variables are also supported.
69+
70+
For more granular control, you can also explicitly set proxies by `Using a custom session`_
71+
as described in the ``requests`` documentation.
4972

5073
Reference:
5174
https://requests.readthedocs.io/en/latest/user/advanced/#proxies
@@ -188,15 +211,3 @@ on your own, such as for nested API responses and ``Union`` return types. For ex
188211
189212
if TYPE_CHECKING:
190213
assert isinstance(license["plan"], str)
191-
192-
Custom session (Bring your own Session)
193-
---------------------------------------
194-
195-
You can use configuration files and a custom session to create
196-
``gitlab.Gitlab`` objects:
197-
198-
.. code-block:: python
199-
200-
gl = gitlab.Gitlab.from_config('somewhere', ['/tmp/gl.cfg'], session=custom_session)
201-
202-

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.