Skip to content
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

Fix no_proxy and no, not being respected. Merge self.proxies and proxies #5596

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Suika
Copy link

@Suika Suika commented Sep 24, 2020

Since no_proxy is not working as intended, I tried fixing it with least intrsion into whole process.
It is contained to the merge_environment_settings and request function. In the request the proxy from request and proxy from session are merged. Having the request proxy overwrite the session proxy where needed.

The should_bypass_proxies is applied outside get_environ_proxies in merge_environment_settings, since no_proxy is only applied to OS ENV and not the proxies set in requests or Sessions

Should close #4871, I hope.

Check if the proxy should be bypassed in case no_proxy or no match the host of the url.
Also, since proxy can be defined in the session and the reuquest itself, both of them were never merged. Now they self.proxies will be updated by proxies.
Make it match the variable being returned
It makes more sense to have the check be outside the trust_env. Since it has to be always executed. Because proxy configuration can be performed on the Sessions class.
That logic was left from previous tires fixing no_proxy and since it's quite compact now, it can be removed and should_bypass_proxies should be used instead of setting a var.
@nateprewitt nateprewitt changed the base branch from master to main January 3, 2022 15:26
@@ -512,6 +512,14 @@ def request(self, method, url,

proxies = proxies or {}

# Update self.proxy with proxy and assing the result to proxies
if isinstance(proxies,dict):
slef_proxies_tmp = self.proxies.copy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo? slef_proxies_tmp should be self_proxies_tmp I suppose?

if isinstance(proxies,dict):
slef_proxies_tmp = self.proxies.copy()
slef_proxies_tmp.update(proxies)
proxies = slef_proxies_tmp.copy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to copy() the dict again. slef_proxies_tmp is already a copy of self.proxies

@RichieB2B
Copy link
Contributor

This patched fixed #5731 for me. I was very surprised this patch has not gotten any attention yet. Is there anything missing before it can be considered?

@kurago-dev
Copy link

Hi @Suika and @RichieB2B, we are also dealing with this issue, any updates?

@RichieB2B
Copy link
Contributor

I found a work around that I described at #5731 (comment) and in #6172

@livenson
Copy link

Hi, we are also being hit by that and would appreciate if this issue would be fixed.

@JMMarchant
Copy link

Also being hit by this; in our case it's setting proxies on the Session instance, but then the call to proxies = merge_settings(...) basically doesn't respect should_bypass_proxy() because it happens later.

@milahu
Copy link

milahu commented Feb 23, 2024

@Suika thank you for your work

any updates?

this issue is known for at least 5 years (#4871)
so i would not wait for "maintainers" to merge this patch

in general, waiting for pypi releases is a bad habit
just add this fork as a git module in vendor/requests
use sys.path.append("vendor/requests/src") and get on with life...

@pinnnkman
Copy link

LGTM, im working for corp env, when setting up a Windows proxy, the 'no' and 'no_proxy' are fail in requests.get('http://localhost:8000', proxies={'http': proxy, 'https': proxy, 'no': 'localhost, 127.0.0.1'})
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

respect no_proxy environment variable and proxies['no'] parameter
7 participants