How do I use a proxy with Python requests?
The short answer
Pass a proxies dict with the same proxy URL under both the "http" and "https" keys: requests.get(url, proxies={"http": p, "https": p}). Put the login in the URL as user:pass@host:port. For SOCKS5, install requests[socks] and use a socks5h:// URL.
Answered by the ProxyCrown team, the people who run the network this is about · Updated
The longer answer
The "https" key is the proxy used for HTTPS targets. Its value still usually starts with http://, because you talk to the proxy over HTTP and tunnel with CONNECT. This trips up almost everyone once.
URL-encode special characters in the password, like @ or :, or the login fails with a 407.
Always set a timeout. Without one, a stuck connection can hang your script forever.
import requests
p = "http://USER:PASS@gw.proxycrown.com:823"
r = requests.get("https://ipinfo.io/json", proxies={"http": p, "https": p}, timeout=30)
print(r.json())