- 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.
- httpx 0.28: the proxy argument, username and password go in the proxy URL
- One Client or AsyncClient per script, set the timeout explicitly (the default is 5 s)
- SOCKS5 after pip install "httpx[socks]", different proxies for different sites through mounts
httpx is an HTTP client for Python with the same API for regular and asynchronous code. You set the proxy with a single argument, proxy, and for more complex setups there is mounts: a separate transport per scheme, domain or port. This guide is written for httpx 0.28: that is the version that removed the deprecated proxies argument, and old examples that use it no longer run.
Step 1. Write the proxy URL with the username for the proxy argument
httpx accepts the username and password right in the proxy address, in the part before @. So you need one line from the dashboard: the scheme, username, password, the host gw.prokso.com and the port. The generator has a format with the protocol at the start for this, and you can paste it into code as is.
The port decides how the address behaves. On 823 (HTTP) and 824 (SOCKS5) every request goes out from a new IP. A port from the 10000-20000 range keeps one address for 1 to 120 minutes and works with both protocols. The country is set in the username, for example username__cr.ua, so for another country only the username changes in the URL.
If the password contains @, : or /, encode them with urllib.parse.quote, otherwise httpx will parse the address incorrectly.
Step 2. Client with proxy and a timeout
import httpx
PROXY = "http://USERNAME:PASSWORD@gw.prokso.com:823"
timeout = httpx.Timeout(30.0, connect=10.0)
with httpx.Client(proxy=PROXY, timeout=timeout) as client: # one client for the whole script
r = client.get("https://api.ipify.org")
r.raise_for_status()
print(r.text)The httpx documentation recommends using Client for anything more serious than a one-off experiment: top-level functions such as httpx.get open a new connection for every request. With a proxy this is especially noticeable, because every new connection is also a new tunnel to the site.
httpx has a timeout enabled by default: 5 seconds of network inactivity. Through a rotating proxy this is sometimes too little, so the example raises the overall limit to 30 seconds and leaves 10 for connecting to the proxy. raise_for_status() turns a response with a non-2xx code into an HTTPStatusError exception.
One more difference from other libraries: httpx does not follow redirects on its own. If the site responds with 301 or 302, add follow_redirects=True to the client.
Step 3. AsyncClient: many requests in parallel
import asyncio
import httpx
PROXY = "http://USERNAME:PASSWORD@gw.prokso.com:823"
async def main():
limits = httpx.Limits(max_connections=20)
async with httpx.AsyncClient(proxy=PROXY, limits=limits, timeout=30.0) as client:
tasks = [client.get("https://api.ipify.org") for _ in range(5)]
for r in await asyncio.gather(*tasks):
print(r.text)
asyncio.run(main())The asynchronous client accepts the same proxy. The documentation specifically warns against creating many client instances and recommends keeping one shared instance, for example a global one. Each instance has its own connection pool.
The pool is limited by httpx.Limits: by default up to 100 connections and 20 kept alive between requests. A Prokso plan allows up to 1000 concurrent connections, so set the limit deliberately, taking into account other scripts on the same plan. In the example, five requests on port 823 return five different IPs.
Step 4. mounts: different ports for different sites
mounts maps an address pattern to a transport. This lets one client send the account login through a sticky port, the rest of the requests through a rotating port, and send one more domain direct.
import httpx
mounts = {
"all://accounts.example.com": httpx.HTTPTransport(proxy="http://USERNAME:PASSWORD@gw.prokso.com:10001"), # sticky port for the account
"all://intranet.local": None, # this domain goes direct
"https://": httpx.HTTPTransport(proxy="http://USERNAME:PASSWORD@gw.prokso.com:823"), # everything else rotates per request
"http://": httpx.HTTPTransport(proxy="http://USERNAME:PASSWORD@gw.prokso.com:823"),
}
client = httpx.Client(mounts=mounts, timeout=30.0)Patterns in httpx have their own logic: all://example.com is only this domain, all://*example.com is the domain together with its subdomains, all://*.example.com is subdomains only. The value None means "no proxy", so internal addresses can go direct without creating a separate client.
Step 5. SOCKS5 through the socks extra
SOCKS support in httpx is optional and is installed together with the package: pip install "httpx[socks]". After that it is enough to change the scheme to socks5:// and the port to 824. The username and password still go in the address.
pip install "httpx[socks]"
python -c 'import httpx; print(httpx.get("https://api.ipify.org", proxy="socks5://USERNAME:PASSWORD@gw.prokso.com:824").text)'Since version 0.28, httpx also accepts the socks5h:// scheme. For Prokso the setup is no different: the host, port and username are the same. If the socksio package is not installed, httpx cannot work with the socks5:// scheme, so check the installation first when SOCKS does not start.
Environment variables and trust_env
Without the proxy argument, httpx reads HTTP_PROXY, HTTPS_PROXY and ALL_PROXY (for http, https and all requests respectively), and NO_PROXY is a comma-separated list of hosts that go direct.
This is handy for third-party tools, but in your own code it can backfire: a variable left in the server environment will quietly send requests through a different proxy or, the other way around, around yours. To make httpx ignore the variables, create the client with trust_env=False.
httpx exceptions and what they mean for a proxy
- ProxyError - a failure while establishing a connection through the proxy. Most often a wrong username or password or used-up traffic on the plan (code 407).
- ConnectTimeout - httpx did not get a connection within
connect. Check the port and scheme:http://on port 824 does not work (proxy timeout). - ReadTimeout - the connection is there, but the response is delayed. Increase
reador retry the request: on port 823 the retry goes out from a different address. - ConnectError - the network did not allow a connection at all, for example access to
gw.prokso.comis blocked by a firewall. - HTTPStatusError - the proxy worked, and the site responded with an error. 403 or 429 come from the site, not from Prokso.
All network exceptions inherit from httpx.RequestError, so for a simple retry it is enough to catch that one.
Check: the IP the script prints
Run the example from step 2: the terminal will show the IP the site sees your request from. It should differ from the IP of your computer or server. Run it again: on port 823 there will be a different address, on a sticky port the same one.
If the script fails, check the line itself in the proxy checker. It works separately from your code and will show right away whether the username and port are correct.
If the proxy does not work
FAQ
Why does an example with proxies= give an error?
The proxies argument was deprecated in httpx 0.26 and removed in 0.28. Replace it with proxy for a single proxy or with mounts if you need different proxies for different addresses.
Do I need to install anything extra for SOCKS5?
Yes, install httpx with the extra: pip install "httpx[socks]". Without it the socks5:// scheme does not work.
Why do requests fail after 5 seconds?
That is the default httpx timeout. Set your own with httpx.Timeout, for example 30 seconds overall and 10 for connecting to the proxy.
How do I stop httpx from taking the proxy from the system?
Create the client with trust_env=False: then the HTTP_PROXY, HTTPS_PROXY and ALL_PROXY variables have no effect.
Does HTTP/2 work through a Prokso proxy?
HTTP/2 in httpx is turned on with the http2=True parameter and requires pip install "httpx[http2]". The proxy does not affect it: the tunnel to the site is the same, and the protocol is negotiated by the client and the site.
Was this guide helpful?
Thanks for your feedback!
Sorry about that. Tell us which step you got stuck on and we will help.