Using a static proxy from curl and Python
Send a request through a static proxy from the command line and from a short Python Requests script, with either kind of authentication.
Updated 2 min read
A static proxy takes the same four values in every client: host, port, username and password. The host and port are on the proxy's page in the dashboard; Finding your host, port and credentials shows where. In the examples, HOST:PORT stands for those values.
Step 1: curl
For a proxy that uses a username and password:
curl -sS -x "http://HOST:PORT" --proxy-user "USERNAME:PASSWORD" https://api.ipify.org; echo
For a proxy set to an IP allowlist, drop the credentials and run the command from the allowlisted machine:
curl -sS -x "http://HOST:PORT" https://api.ipify.org; echo
Expected result: one address, the one shown on the proxy's page.
Step 2: Python Requests
import requests
proxy = "http://USERNAME:PASSWORD@HOST:PORT"
response = requests.get(
"https://api.ipify.org",
proxies={"http": proxy, "https": proxy},
timeout=30,
)
print(response.text)
For an IP allowlist, use proxy = "http://HOST:PORT". Set a timeout on every request so that a stalled connection fails instead of hanging.
Choosing the authentication
Which one to use, and how to set it up, is covered in Authenticating with username and password and Authenticating by IP allowlist. A password with special characters must be percent-encoded in the proxy URL; the first of those articles shows how.
If it fails
| Symptom | Read |
|---|---|
A 407 or 403 |
|
A timeout, a refused connection or a reset |
For the full set of checks before production use, see Testing a proxy before production use.