Code / Python Requests

How to Use Proxies with Python Requests

Pass a proxy URL to Python Requests for both HTTP and HTTPS traffic. The examples below use your Typroxy connection details and return the public IP seen by the destination, with a timeout to avoid waiting indefinitely.

Last checked:

Before you start

Get your proxy details from Dashboard → Proxies. You'll need the host, port, username and password.

Replace HOST, PORT, USERNAME and PASSWORD in the examples with your own details. Use the port that matches your connection type.

Get a proxy

Code examples

HTTP proxy

Install dependencies

pip install requests
import requests

proxy = "http://USERNAME:PASSWORD@HOST:PORT"
proxies = {"http": proxy, "https": proxy}

r = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
print(r.json())

SOCKS5 proxy

Install dependencies

pip install "requests[socks]"
import requests

proxy = "socks5h://USERNAME:PASSWORD@HOST:PORT"
proxies = {"http": proxy, "https": proxy}

r = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
print(r.json())

socks5h means DNS lookups also go through the proxy. If your password contains special characters like @ or :, URL-encode it first.

Check it worked

Run the example above to open https://api.ipify.org?format=json through the proxy. The IP shown should be your proxy's IP, not your own.

Read the IP printed by the script, rather than opening the link in an unconfigured browser. A rotating proxy's IP can change between requests.

Troubleshooting

407 Proxy Authentication Required
Username or password is wrong; copy them again from the dashboard.
Connection timed out / refused
Check host and port, and that the proxy is Active (not expired) in the dashboard.
IP shows my own address
The proxy isn't applied; re-check the settings and restart the browser profile or script.
Wrong country
Check which location you bought in the dashboard.

Still stuck? Open a support ticket — include your order ID.

Frequently asked questions

Need a proxy for this?

Static residential proxies work best for account management; rotating residential for scraping.