Syntax proxies ' = {"protocol":"ip:port", ...} . With it, you can specify different (or the same) proxies for requests using the http, https and ftp protocols:
http_proxy = "http://10.10.1.10:3128" https_proxy = "https://10.10.1.11:1080" ftp_proxy = "ftp://10.10.1.10:3128" proxyDict = { "http" : http_proxy, "https" : https_proxy, "ftp" : ftp_proxy } r = requests.get(url, headers=headers, proxies=proxyDict)
Derived from documentation requests :
Options:
method - the method for the new Request object.
url - URL for the new Request object.
...
proxies - (optional) The dictionary maps the protocol to the proxy server URL .
...
On linux, you can also do this using the environment variables HTTPS_PROXY , HTTPS_PROXY and FTP_PROXY :
export HTTP_PROXY=10.10.1.10:3128 export HTTPS_PROXY=10.10.1.11:1080 export FTP_PROXY=10.10.1.10:3128
On Windows:
set http_proxy=10.10.1.10:3128 set https_proxy=10.10.1.11:1080 set ftp_proxy=10.10.1.10:3128
Thank you, Jay for pointing this out:
Syntax changed using 2.0.0 queries .
You will need to add the schema to the URL: http://docs.python-requests.org/en/latest/user/advanced/#proxies
chown Nov 27 '11 at 18:08 2011-11-27 18:08
source share