GBProxies

How to Use Proxies with Python requests

Python requests takes a proxies dictionary with one URL per scheme. Put your proxy username and password in the URL and every request goes through the gateway.

Steps

  1. Install requests with pip install requests
  2. Copy your proxy username and password from the console
  3. Build the proxy URL with the gateway host and the product port
  4. Pass it as proxies= to every request or to a Session

Example code

import requests

user = "USERNAME-cc-us"   # country code is optional
password = "PASSWORD"
proxy = f"http://{user}:{password}@gw.gbproxies.cc:10000"

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

Replace USERNAME and PASSWORD with the proxy login from the Proxies page of the console. Port 10000 is residential HTTP; see the ports of every product below.

Tips

  • Use a requests.Session to reuse connections; add -sid-<id>-ttl-<minutes> to keep the same IP
  • For SOCKS5 install requests[socks] and use socks5h:// with port 10001

Common questions

Why do I get a 407 error?

407 means the gateway did not accept the login. Check the username, the password and that the product has GB left.

How to Use Proxies with Python requests