Guide
How to Use an HTTP or SOCKS5 Proxy with cURL, Python and Node.js
By AptProxy · Updated
Every AptProxy proxy uses username and password authentication. In My Proxies you can copy each proxy as IP:Port:User:Pass, User:Pass@IP:Port or IP:Port only, and switch between the HTTP port and the SOCKS5 port where a SOCKS5 port exists. The examples below use the documentation address 203.0.113.10 and placeholder credentials; replace them with your own.
1. Build the proxy URL
Most tools accept a single proxy URL: scheme, credentials, host and port. Use http:// with the HTTP port and socks5h:// with the SOCKS5 port. The h in socks5h means DNS is resolved by the proxy, so the target's hostname never leaks to your local resolver.
http://USER:PASS@203.0.113.10:8000
socks5h://USER:PASS@203.0.113.10:8001If the password contains characters such as @, : or /, URL-encode it first (encodeURIComponent in JavaScript, urllib.parse.quote in Python).
2. cURL
# HTTP proxy
curl -x http://USER:PASS@203.0.113.10:8000 https://api.ipify.org?format=json
# SOCKS5 proxy (DNS resolved by the proxy)
curl -x socks5h://USER:PASS@203.0.113.10:8001 https://api.ipify.org?format=jsonThe response shows the IP address the website sees. It should be the proxy's IP, not yours.
3. Python (requests)
import requests
proxy = "http://USER:PASS@203.0.113.10:8000"
proxies = {"http": proxy, "https": proxy}
r = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
print(r.json())For SOCKS5, install the SOCKS extra and change the scheme:
# pip install "requests[socks]"
proxy = "socks5h://USER:PASS@203.0.113.10:8001"
proxies = {"http": proxy, "https": proxy}4. Node.js (axios)
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
const agent = new HttpsProxyAgent("http://USER:PASS@203.0.113.10:8000");
const { data } = await axios.get("https://api.ipify.org?format=json", {
httpsAgent: agent,
proxy: false, // let the agent handle the proxy
});
console.log(data);For SOCKS5, use socks-proxy-agent instead:
import { SocksProxyAgent } from "socks-proxy-agent";
const agent = new SocksProxyAgent("socks5h://USER:PASS@203.0.113.10:8001");
const { data } = await axios.get("https://api.ipify.org?format=json", {
httpAgent: agent,
httpsAgent: agent,
proxy: false,
});5. Fixing common errors
- 407 Proxy Authentication Required: the username or password is wrong, or a special character in the password was not URL-encoded.
- Connection refused or reset right away: the port and protocol do not match, for example a SOCKS5 URL pointed at the HTTP port. Copy the port for the protocol you use.
- IPv6 proxies time out on some sites: IPv6 proxies only reach targets that support IPv6. Test with an IPv6-capable endpoint such as https://api64.ipify.org. IPv6 orders are HTTPS or SOCKS5, chosen when you order (minimum 10 IPs).
- An IP shows as pending: the provider is still allocating it. Press Sync on the order to fetch it once it is ready.
You can also check that a proxy responds, and see its latency, with the ping button on the order page.