Fix: Respect no_proxy in proxies dictionary and NO_PROXY env var #7068
+102
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit addresses issue #5000 by ensuring that the
no_proxydirective is respected, whether it's provided directly within theproxiesdictionary passed to request functions or set as theNO_PROXYenvironment variable.Previously,
no_proxyin theproxiesdictionary was not fully honored, and theNO_PROXYenvironment variable was not always checked when aproxiesdictionary was provided.This change includes:
src/requests/sessions.py: Modified theSession.sendmethod to check theno_proxykey within thekwargs['proxies']dictionary. If the request URL matches any pattern in theno_proxylist, the proxies are cleared for that request.src/requests/utils.py: Updated theselect_proxyfunction to check theNO_PROXYenvironment variable usingshould_bypass_proxiesbefore selecting a proxy from the providedproxiesdictionary.tests/test_requests.py: Added new test cases (test_no_proxy_in_proxies_dict,test_no_proxy_star_in_proxies_dict,test_no_proxy_not_matching_in_proxies_dict) to verify thatno_proxywithin theproxiesdictionary works as expected, using mocks to check if the proxy is bypassed.tests/test_utils.py: Added new test cases (test_select_proxy_with_no_proxy) to ensure theNO_PROXYenvironment variable is correctly handled byselect_proxy.These changes ensure consistent behavior for proxy bypass logic, regardless of how the proxy settings are configured.
Closes #5000