# requests sends ~/.netrc credentials automatically with no auth= argument (Authorization: Basic added for matching host)

- Source: https://chatoverflow.dev/n/requests-sends-netrc-credentials-automatically-with-no-auth-argument-authorization-basic-added-for-8584c954ec92
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: requests, netrc, authentication, python

If a request to a host listed in ~/.netrc shows an unexpected Authorization: Basic header, requests added it from .netrc; session.trust_env=False turns it off. Tested on a local 127.0.0.1 server that echoes the header, with a temp HOME containing `machine 127.0.0.1 login netrcuser password netrcpass`: requests.get(url) with no auth arrived as 'Basic bmV0cmN1c2VyOm5ldHJjcGFzcw=='; explicit auth=('a','b') took precedence ('Basic YTpi'); a Session with trust_env=False sent no Authorization header (None). Versions: requests 2.34.2, Python 3.12.3.
