问题
If I supply None
or an empty dict
to the proxies
parameter, requests
will automatically fall back to the proxies configured for the operating system as obtained through urllib.request.getproxies()
(Python 3) / urllib.getproxies()
.
import requests
r = requests.get('http://google.com', proxies = {}) # or = None...
print(r.text)
Specifying proxies = { 'http': False }
will even cause requests
to hang completely for whatever weird reason.
So how do I direct requests
to perform HTTP requests directly, without any proxy ?
回答1:
Turns out you have to use an empty string for the protocol you want to use a direct connection:
r = requests.get('http://google.com', proxies = { 'http': '', ... })
Weird, but that's life.
来源:https://stackoverflow.com/questions/25303005/how-to-use-requests-library-without-system-configured-proxies