Sous proxy / Integrations / Python httpx

Proxy in httpx: HTTP and SOCKS5

In httpx a proxy is one string in the proxy parameter. Here are HTTP and SOCKS5 with a password, plus the errors after upgrading to 0.28.

HTTPHTTPSSOCKS5Login and passwordRotation and sticky
Python httpx · proxy
http://LOGIN:PASSWORD@HOST:PORT
socks5://LOGIN:PASSWORD@HOST:PORT
15
✓ IP: Germany, residentialRun

Why use a proxy in Python httpx

httpx is a Python HTTP client with sync and async APIs. The proxy is passed in the proxy parameter of httpx.Client or httpx.AsyncClient, with login and password right in the URL. SOCKS5 needs the extra httpx[socks] dependency.

What to pick

Start with HTTP: it works without extra packages. Add SOCKS5 only if you need it specifically, for example for UDP tasks on residential proxies. Rotation for scraping, a sticky session for working with one account.

Residential

from $0.6 / GB

Home ISP addresses. The main choice for accounts and protected sites.

VIP

$2 / GB

Hand-picked clean IPs, faster and more stable than regular residential.

Mobile

$4 / GB

Carrier IPs, for platforms that check addresses strictly.

Step-by-step setup

Button names are given exactly as they appear in Python httpx.

  1. Install httpx

    Run pip install httpx. For SOCKS5 install pip install "httpx[socks]" right away.

  2. Export the proxy

    Take the login:pass@ip:port format in @SousProxyBot or the dashboard and add the http:// or socks5:// scheme. Encode special characters in the password, e.g. with /en/tools/proxy-converter/.

  3. Pass proxy to the client

    Create httpx.Client(proxy=proxy). One client keeps connections and the proxy for all requests inside the with block.

  4. Run it

    Save the example as ip.py and run python ip.py.

  5. Check the IP

    The script prints JSON with an address. It must differ from what /en/tools/my-ip/ shows without a proxy.

Code example

Put in your own HOST, PORT, LOGIN and PASSWORD from the bot or the dashboard.

python
import httpx

proxy = "http://LOGIN:PASSWORD@HOST:PORT"
# SOCKS5: pip install "httpx[socks]" and
# proxy = "socks5://LOGIN:PASSWORD@HOST:PORT"

with httpx.Client(proxy=proxy, timeout=15) as client:
    r = client.get("https://api.ipify.org?format=json")
    print(r.json())

Tested by running it

We ran this example ourselves: Python 3.13.18 · httpx 0.28.1. Real output below, IP hidden.

Terminal · ip.py
$ python ip.py
{'ip': 'proxy IP'}

And this is the response when the password is wrong:

$ python ip.py
…
    ~~~~~~~~~~~~~~^^^^^^^
  File "/home/user/proxy-test/.venv/lib/python3.13/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ProxyError: 407 Proxy Authentication Required

Common errors

The issues people most often bring to support.

!

TypeError: unexpected keyword argument 'proxies'httpx 0.28 removed the proxies parameter. Write proxy="..." with one string, and use mounts for different schemes.

!

ImportError: Using SOCKS proxy, but the 'socksio' package is not installedThe SOCKS dependency is missing. Run pip install "httpx[socks]".

!

ProxyError or a 407 responseWrong login or password, or special characters in the password aren't encoded. Run the password through urllib.parse.quote.

!

ReadTimeout on some requestsWith rotation some IPs are slower. Raise the timeout and test the line on /en/tools/proxy-checker/.

Need a proxy for Python httpx?

Residential, VIP and mobile IPs. HTTP and SOCKS5, pay per GB, 1 GB free to try.

FAQ

How do I do the same in async code?

The same way, via httpx.AsyncClient(proxy=proxy) and await client.get(...). The proxy parameter is identical for the sync and async clients.

Can I route only some addresses through the proxy?

Yes, with mounts: pass a dict like {"https://": httpx.HTTPTransport(proxy=proxy)}. Other addresses go direct.

Does httpx read HTTP_PROXY and HTTPS_PROXY?

Yes, if no proxy is passed and trust_env isn't disabled. An explicit proxy parameter in code is more reliable.