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

Environment variables take precedence over the explicitly passed proxies argument in session.get() #6798

Closed
pracon-cmd opened this issue Sep 5, 2024 · 1 comment
Labels
actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug

Comments

@pracon-cmd
Copy link

Environment:
uname -a
Linux 6.1.0-25-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.106-3 (2024-08-26) x86_64 GNU/Linux
pip list
Package Version


certifi 2024.8.30
charset-normalizer 3.3.2
idna 3.8
pip 23.0.1
requests 2.32.3
setuptools 66.1.1
urllib3 2.2.2

Is that normal that the Environment variables: HTTP_PROXY and HTTPS_PROXY would override the proxies argument passed to session.get()?

test code:
`import requests
import os

Disable environment proxies temporarily

#os.environ.pop('https_proxy', None)
#os.environ.pop('http_proxy', None)

get all environs

print(os.environ)

Define a test URL (you can replace this with a URL of your choice)

test_url = 'http://httpbin.org/ip'

Define your custom proxies

my_proxies = None

Create a session

session = requests.Session()

Test session.get with explicitly defined proxies

print("=== Session GET with my_proxies ===")
response = session.get(url=test_url, proxies=my_proxies)

Print the result (should reflect the proxy being used)

print(f'Your IP (using my_proxies): {response.json().get("origin")}')`

Run it and you will notice that the session uses the proxy server instead of None (specified by my_proxies = None)

@pracon-cmd pracon-cmd added actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug labels Sep 5, 2024
Copy link

github-actions bot commented Sep 5, 2024

As described in the template, we won't be able to answer questions on this issue tracker. Please use Stack Overflow

@github-actions github-actions bot closed this as completed Sep 5, 2024
@github-actions github-actions bot locked as off-topic and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug
Projects
None yet
Development

No branches or pull requests

1 participant