# Python Requests with a static proxy

> Python Requests with a static proxy: tested code for HTTP and SOCKS5, an exit-IP check and one IP per account. SteadyProxy IPs from $2.24, no KYC, crypto.

- URL: https://steadyproxy.com/guides/python-static-proxy/
- Last updated: 2026-10-19
- Publisher: SteadyProxy (https://steadyproxy.com)

Build the proxy URL from your IP's four values, pass it for http and https, set timeouts and check the exit IP. Tested on 19 October 2026.

**Quick answer — How do I use Python Requests with a static proxy?**

To use Python Requests with a static proxy, build the proxy URL from the host, port, username and password of your IP. Pass it for both the http and https keys of proxies=, set a timeout, and check the exit IP at api.ipify.org. **SteadyProxy** static IPs cost $2.24 for 30 days as of October 2026, with no KYC and crypto payment.

## What are the key facts?

| Attribute | Value |
| --- | --- |
| Install | python -m pip install requests (SOCKS5: requests[socks]) |
| HTTP proxy URL | http://USERNAME:PASSWORD@host:port, for both the http and https keys |
| SOCKS5 proxy URL | socks5h://USERNAME:PASSWORD@host:port (default SOCKS5 port 7778) |
| Special characters | URL-encode the username and password with urllib.parse.quote |
| Environment proxies | session.trust_env = False ignores HTTP_PROXY set elsewhere |
| Timeouts | (10, 30): 10 s to connect, 30 s to read, in our examples |
| Tested | Python 3.14 and Requests 2.34, 19 October 2026, through a password-protected test proxy |

## How do I send a request through one static proxy?

Each static IP comes with its own host, port, username and password in your dashboard. Put them in environment variables, not in the code. The script below builds the proxy URL, sends one request to api.ipify.org, and stops if the exit IP is not the one you expect. It then reads the network name from ipinfo.io. With a wrong password, Requests raises a ProxyError that mentions 407 Proxy Authentication Required, as our test showed.

*python_requests.py: one static proxy with an exit-IP check*

```python
"""Python Requests through one static proxy, with a check of the exit IP.

Install: python -m pip install requests
"""
import os
from urllib.parse import quote

import requests

HOST = os.environ.get("PROXY_HOST", "gw.steadyproxy.com")
PORT = os.environ.get("PROXY_PORT", "7777")
USER = quote(os.environ.get("PROXY_USER", "USERNAME"), safe="")
PASSWORD = quote(os.environ.get("PROXY_PASS", "PASSWORD"), safe="")
EXPECTED_IP = os.environ.get("EXPECTED_IP")  # the static IP listed in your dashboard

# The proxy URL starts with http:// even for https:// sites (Requests opens a CONNECT tunnel)
PROXY = "http://" + USER + ":" + PASSWORD + "@" + HOST + ":" + PORT
PROXIES = {"http": PROXY, "https": PROXY}

with requests.Session() as session:
    session.trust_env = False  # ignore HTTP_PROXY / HTTPS_PROXY set elsewhere on the machine
    response = session.get("https://api.ipify.org?format=json", proxies=PROXIES, timeout=(10, 30))
    response.raise_for_status()
    exit_ip = response.json()["ip"]
    print("Exit IP:", exit_ip)
    if EXPECTED_IP and exit_ip != EXPECTED_IP:
        raise SystemExit("Exit IP differs from the static IP you expected")

    page = session.get("https://ipinfo.io/json", proxies=PROXIES, timeout=(10, 30))
    page.raise_for_status()
    print("Network:", page.json().get("org"), "-", page.json().get("country"))

```

## Why is the proxy URL http:// for https:// sites?

The key of the proxies dictionary is the scheme of the target site; the value is the address of the proxy. For an https:// site, Requests asks the HTTP proxy to open a CONNECT tunnel, then runs TLS through it to the site. The proxy never sees the decrypted page. So both keys point to the same http:// proxy URL. Keep certificate checks on: never set verify=False to make a proxy error go away.

## How do I give each account its own static IP?

Map each account or job to one IP and build one Session per mapping. A Session keeps cookies and reuses connections, and with trust_env = False its proxies setting is not replaced by environment variables. The example below reads one line per IP, in the order host, port, username, password, which you can copy from the four values in your dashboard.

*python_per_account.py: one Session per static IP*

```python
"""One static IP per account or per job with Python Requests.

Each line holds the four values shown for one IP in your dashboard:
host:port:username:password
"""
import os
from urllib.parse import quote

import requests

STATIC_IPS = {
    "store-uk": os.environ.get("PROXY_STORE_UK", "gw.steadyproxy.com:7777:USERNAME:PASSWORD"),
    "store-de": os.environ.get("PROXY_STORE_DE", "gw.steadyproxy.com:7777:USERNAME:PASSWORD"),
}


def session_for(name):
    host, port, user, password = STATIC_IPS[name].split(":", 3)
    proxy = "http://" + quote(user, safe="") + ":" + quote(password, safe="") + "@" + host + ":" + port
    session = requests.Session()
    session.trust_env = False
    session.proxies = {"http": proxy, "https": proxy}
    return session


for account in STATIC_IPS:
    with session_for(account) as s:
        ip = s.get("https://api.ipify.org", timeout=(10, 30)).text
        print(account, "->", ip)

```

## How do I use SOCKS5 instead of HTTP?

Install requests[socks] and replace http:// with socks5h:// and the HTTP port with the SOCKS5 port. The h makes the proxy resolve hostnames, so DNS answers match the IP's country. The rest of the code stays the same. A complete, tested example is in the [SOCKS5 static proxy guide](https://steadyproxy.com/guides/socks5-static-proxy/). Both ports of one static IP lead to the same exit IP.

## What do the common errors mean?

Each error points to one layer.

- **ProxyError with 407**: wrong username or password, or this machine is not on your allowlist.
- **ConnectTimeout**: wrong host or port, or a firewall on your side blocks outgoing traffic to the proxy port.
- **ReadTimeout**: the target or the path is slow; retry later and keep the read timeout.
- **SSLError**: a certificate problem on the target or on your machine; do not disable verification.
- **403 or 429 from the target**: the site refused or rate-limited the request; slow down.

If one IP fails every request for an hour, contact support. Our replacement rule: If an IP does not work, write to support: we repair it or replace it with another IP in the same country when stock allows.

## What else do people ask about Python and static proxies?

### Why do I set both the http and https keys?

Requests picks the proxy by the scheme of the target URL. Without the https key, requests to https:// sites would go out directly, from your own IP. Setting both keys to the same proxy URL sends every request through the static IP. The api.ipify.org check in the script catches a missing key at once.

### Why URL-encode the username and password?

Characters such as @, : and / have a meaning inside a URL. A password with an @ would otherwise be read as the end of the login part. urllib.parse.quote with safe='' encodes them, and Requests decodes them before it sends the login to the proxy. This works for both HTTP and socks5h:// URLs.

### Why set trust_env to False?

Requests reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY from the environment by default, and the documentation warns that environment proxies can override a Session's proxies setting. A VPN or corporate setting could then route some requests elsewhere. trust_env = False makes the code use only the proxy you pass.

### Can I use the same code with httpx or aiohttp?

Yes, the idea is the same: a proxy URL built from host, port, username and password, plus a timeout and an exit-IP check. The parameter names differ by library and version, so follow that library's proxy documentation. Keep one client per static IP, as with Sessions in Requests.

### How do I keep credentials out of my repository?

Read them from environment variables or a secret manager, as the examples do, and never commit a .env file with real values. Do not print the proxy URL in logs, because it contains the password. With the IP allowlist method, scripts on allowlisted machines need no proxy password at all.

### How many requests can one static IP handle in Python?

The proxy bills per IP and per 30 days, not per GB. Billed per IP and per 30 days, not per GB; fair use applies. The real limit is the target site, which may rate-limit one IP. Keep concurrency modest per IP, add delays, and follow each site's terms. For more volume on one task, spread work across several IPs; see [how many static IPs do I need?](https://steadyproxy.com/guides/how-many-static-ips/).

## Which sources does this guide use?

1. [Requests advanced usage: proxies, SOCKS, timeouts](https://requests.readthedocs.io/en/latest/user/advanced/) — Requests (2026-10-19)
2. [urllib.parse: quote](https://docs.python.org/3/library/urllib.parse.html) — Python Software Foundation (2026-10-19)
3. [ipify API](https://www.ipify.org/) — ipify (2026-10-19)

---

SteadyProxy: SteadyProxy is a static proxy provider: ISP (static residential) and dedicated datacenter IPs rented per IP for 30 days, paid in crypto with no ID upload.
