Proxy setup in httpx

Proxies in httpx for Python: the proxy parameter on Client and AsyncClient, credentials in the URL, SOCKS5 via httpx[socks] and choosing a port.

Updated · Prokso editorial team

Connection details
Host
gw.prokso.com
Port
823 HTTP · 824 SOCKS5 — new IP per request · 10000–20000 sticky session, HTTP(S) and SOCKS5
Username and password
in your dashboard, on the plan page

Your dashboard generates ready-made lines in the format you need: choose the country, IP type and protocol.

Key takeaways
  • Host gw.prokso.com, ports 823 (HTTP), 824 (SOCKS5), 10000–20000 (sticky sessions, HTTP or SOCKS5)
  • The username and password are in your dashboard on the plan page
  • Check the IP in the response of the proxied request itself: the My IP page in a browser does not test your script

A step-by-step guide to connecting Prokso proxies in httpx. It takes a few minutes.

Step 1. Get the proxy details from your dashboard

Open your plan and copy the host gw.prokso.com, port, username and password. Port 823 is HTTP and 824 is SOCKS5 (both give a new IP for every request); ports 10000–20000 keep one IP (sticky session) for up to 120 minutes and work as both HTTP and SOCKS5 (each port is a separate address). Set the country in the username: username__cr.ua.

Step 2. Install the library

pip install httpx. For SOCKS5: pip install "httpx[socks]". The examples below are for httpx 0.28, where the proxy is passed with the proxy parameter; the old proxies parameter has been removed.

import httpx

PROXY = "http://USERNAME:PASSWORD@gw.prokso.com:823"

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

Step 3. Pass the proxy to the client

Create an httpx.Client with the proxy parameter and put the username and password straight into the URL. All requests from this client go through the proxy and reuse connections to it, which is faster than a separate httpx.get for every request.

import asyncio
import httpx


async def main():
    async with httpx.AsyncClient(proxy="socks5://USERNAME:PASSWORD@gw.prokso.com:824", timeout=30) as client:
        urls = ["https://api.ipify.org?format=json"] * 3
        for r in await asyncio.gather(*(client.get(u) for u in urls)):
            print(r.json())


asyncio.run(main())

Step 4. Async requests and SOCKS5

httpx.AsyncClient takes the same parameter. For SOCKS5 change the scheme to socks5:// and the port to 824: httpx sends the website name to the proxy, so DNS lookups don't bypass it.

Step 5. Pick a port for the job

For parallel data collection keep 823 or 824, and every request gets a new address. To send a series of requests from one IP, use a sticky port from 10000-20000: it works with both http:// and socks5://.

Step 6. If the connection fails

Check the host gw.prokso.com, the port and the scheme: HTTP on 823, SOCKS5 on 824, either one on ports 10000-20000. A 407 error means a wrong username or password, or the plan has run out of traffic: check the balance on the plan page in your dashboard. A timeout most often means a typo in the port or a client expecting a different protocol. If you use the IP whitelist, make sure the external address of the exact machine running the code is on the list.

Step 7. Check the output

Run the example: the script calls https://api.ipify.org and prints the IP the website sees. It should be the proxy's address, not yours. A 407 error means a wrong username or password, or the plan has run out of traffic. The My IP page in your browser won't help here: the browser goes direct.

FAQ

Does httpx read the proxy from environment variables?

Yes, by default httpx reads <code>HTTP_PROXY</code> and <code>HTTPS_PROXY</code>. If you pass the <code>proxy</code> parameter, that one wins. To keep the variables from affecting the script, create the client with <code>trust_env=False</code>.

What does ProxyError: 407 mean?

The proxy rejected the username or password. Copy the line from the dashboard generator again and check that the plan still has traffic.

Which port should I use?

Port 823 (HTTP) or 824 (SOCKS5) gives a new IP on every request, which suits data collection. A port from 10000-20000 keeps one IP for up to 120 minutes, for sessions where you sign in to an account. A plan allows up to 1,000 concurrent connections.

How do I choose a country?

The country is part of the proxy username. Generate a line for the country you need in the dashboard and use its username in the code; the rest of the address stays the same.

What if some requests fail?

When collecting data, some addresses can be slow or unavailable. Add a few retries with a pause to your code: on port 823 or 824 every retry goes out from a new address.