Home >Backend Development >Python Tutorial >How to Properly Configure Proxies with Python\'s `requests` Module?
When configuring a 'Requests' request using the 'proxies' parameter, it's essential to understand the expected format of the value. Contrary to immediate assumptions, it's not sufficient to provide an "IP:PORT" string.
Instead, the 'proxies' parameter expects a dictionary in the following format:
{ "protocol1": "scheme1://ip1:port1", "protocol2": "scheme2://ip2:port2", ... }
Consider the following example:
http_proxy = "http://10.10.1.10:3128" https_proxy = "https://10.10.1.11:1080" ftp_proxy = "ftp://10.10.1.10:3128" proxies = { "http": http_proxy, "https": https_proxy, "ftp": ftp_proxy } r = requests.get(url, headers=headers, proxies=proxies)
In this example:
Alternatively, instead of using the 'proxies' parameter, you can set environment variables to configure proxies on Linux and Windows:
Linux:
export HTTP_PROXY=10.10.1.10:3128 export HTTPS_PROXY=10.10.1.11:1080 export FTP_PROXY=10.10.1.10:3128
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
The above is the detailed content of How to Properly Configure Proxies with Python\'s `requests` Module?. For more information, please follow other related articles on the PHP Chinese website!