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

no_proxy setting ignores the proxies dictionary #5000

Open
ofek opened this issue Feb 24, 2019 · 3 comments
Open

no_proxy setting ignores the proxies dictionary #5000

ofek opened this issue Feb 24, 2019 · 3 comments

Comments

@ofek
Copy link
Contributor

ofek commented Feb 24, 2019

These work:

$ python -c "import os,requests;os.environ['HTTPS_PROXY']='https://b.r.o.k.e.n.com';requests.get('https://google.com', proxies={'no_proxy': 'google.com'})"
$ python -c "import os,requests;os.environ['HTTPS_PROXY']='https://b.r.o.k.e.n.com';os.environ['NO_PROXY']='google.com';requests.get('https://google.com')"

These do not work:

$ python -c "import requests;requests.get('https://google.com', proxies={'https': 'https://b.r.o.k.e.n.com', 'no_proxy': 'google.com'})"
$ python -c "import os,requests;os.environ['NO_PROXY']='google.com';requests.get('https://google.com', proxies={'https': 'https://b.r.o.k.e.n.com'})"

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.8"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.5"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.21.0"
  },
  "system_ssl": {
    "version": "100020bf"
  },
  "urllib3": {
    "version": "1.24.1"
  },
  "using_pyopenssl": false
}

cc @Lukasa @sigmavirus24

@cocobear
Copy link

Many issue (#4871, #879, #4600 ) is relative to no_proxy, and this is definitely a bug, even someone provide some patched code, why it's still unresolved?

@AvitalL
Copy link

AvitalL commented Apr 18, 2019

Please fix the issue as it causes a slightly bigger issue - the session.send() method is ignoring the os.environ proxy settings so there is not way to specify proxy settings other than passing proxies explicitly, which doesn't bypass and ignores no_proxy.

@florimondmanca
Copy link

florimondmanca commented Jul 2, 2020

A possible hint looking at the logic for "should we bypass proxies" in Requests, is that this logic is only checked on redirects…

bypass_proxy = should_bypass_proxies(url, no_proxy=no_proxy)

When I would expect it to also be called on each request to decide "should we use proxies for this URL". Eg in .get_adapter(), or whichever place is responsible for saying "use the connection pool, or a proxy":

def get_adapter(self, url):
"""
Returns the appropriate connection adapter for the given URL.
:rtype: requests.adapters.BaseAdapter
"""
for (prefix, adapter) in self.adapters.items():
if url.lower().startswith(prefix.lower()):
return adapter
# Nothing matches :-/
raise InvalidSchema("No connection adapters were found for {!r}".format(url))

But I'm not 100% sure at which layer the proxies vs connection pool decision occur, eg if it's in the default HTTPAdapter or elsewhere (haven't dug that far into the code).

For what it's worth, the 2nd failing test case works as expected with HTTPX:

>>> import os, httpx
>>> os.environ['no_proxy'] = 'google.com'
>>> proxies = {'https': 'https://no.where.com'}
>>> c = httpx.Client(proxies=proxies)
>>> c.get('https://google.com')
<Response [200 OK]>

The 1st failing test case doesn't though, because no_proxy keys aren't taken into account yet by HTTPX (see encode/httpx#1043).

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

No branches or pull requests

4 participants