-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'NoneType' object has no attribute 'setdefault' on environment proxies #6699
Comments
How are you encountering this? On which versions? Why did you skip the issue template? |
Hello! Apologies for not using the template above. I have included it below. Additionally, I have unearthed more context while working on reproduction steps. It appears that although the type hint signature in typeshed defines the proxies parameter as optional: https://github.com/python/typeshed/blob/main/stubs/requests/requests/sessions.pyi#L307 In practice requests fallbacks to an empty dictionary which prevents hitting the issue: https://github.com/psf/requests/blob/main/src/requests/sessions.py#L577 Expected ResultNo Exception to be thrown. Actual ResultAttributeError: 'NoneType' object has no attribute 'setdefault' Reproduction StepsInvoke this code with an environment that has a variable that ends with _PROXY, example: HELLO_PROXY=abc python script.py from requests import Request, Session
request = Request(method="GET", url="<https://disney.com")>
session = Session()
prepared_request = session.prepare_request(request)
settings = session.merge_environment_settings(prepared_request.url, None, None, None, None)
response = session.send(prepared_request, **settings) System Information
|
I'd looked at this when the ticket first opened and the typing is due to ambiguity created by our top-level API defaults and the code inside merge_environment_settings. We imply |
AttributeError: 'NoneType' object has no attribute 'setdefault' on environment proxies
It appears there is a small bug in
Session.merge_environment_settings
where the proxies variable can beNone
but setdefault is called on it anyway when env_proxies are present, causing an AttributeError to be thrown:https://github.com/psf/requests/blob/main/src/requests/sessions.py#L759-L762
The text was updated successfully, but these errors were encountered: