-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Strange difference between passing proxy as None vs an empty string #6153
Comments
Stepping through the code with breakpoints I noticed a difference in the function "rebuild_proxies" which seems to get called when a redirect occurs. In the empty string case we already have "" defined as http(s) proxy so nothing gets overwritten. In the None case the keys for http(s) proxies are absent so they get set using get_environ_proxies. |
Looks like the function merge_setting in the sessions.py module explicitly deletes any Nones (check the variable none_keys). This means http and https proxies end up missing from the dictionary which works fine for the first request, but rebuild_proxies tries to add them back in for the redirect. |
Hi @xjcl, this is the expected behavior and generally how the library operates. What you're trying to accomplish here though is already supported without trying to override the proxies with null values. If you set |
Going to resolve this since we haven't heard back. Feel free to reopen if you have further questions or find the recommended approach isn't working. |
@nateprewitt The use case here is to disable the proxies without the other side effects of |
@jtpereyda would you mind providing a concrete example of the other side effects you're trying to avoid? |
@nateprewitt Are all the effects documented anywhere? I have read that trust_env also ignores:
Both of which are relevant for some of my use cases. |
.netrc info can be supplied via the The original question was about the difference between an empty string and |
At work we have to deal with an annoying proxy server when making automated HTTP requests, e.g. in Python. To deal with this we usually add
proxies={"http": None, "https": None}
to any request, but recently this started breaking down when we started receiving HTTP redirects (301 Moved Permanently). After struggling with this issue by trying out different versions of dependencies, we finally figured out that passing an empty string vs None produced different behavior, with the behavior of None being strictly worse.Reproduction Steps
To reproduce this you need some kind of proxy server setup, I cannot give instructions on how to achieve this.
Code snippet "empty string":
Code snippet "None":
Code snippet "(no proxies)":
Expected Result
Using uppercase Pillow should result in a successful HTTP request (200).
Using lowercase pillow should result in a redirect to uppercase Pillow (301) which
requests
resolves with a second GET that is successful (200).Actual Result
Unexpected result in italic:
I will shorten the actual very long set of 3 tracebacks we receive to:
It is not surprising that we get an SSLError when using no proxy parameter, but I find it odd that there is a semantic difference between passing
None
and""
, (empty string), and could not find any documentation referencing that difference.Further reading on StackOverflow: https://stackoverflow.com/a/72529216/2111778
System Information
The text was updated successfully, but these errors were encountered: