Skip to content
Esc

Articles

What is a proxy? A plain-English guide for beginners: how it works, the types, and what it's forWhat is a 4G proxy? How mobile proxies work, pros, cons and when to use oneRotating proxies explained: rotation types and how to change a proxy IP with a linkSOCKS5 vs HTTP proxies: what's the difference and which should you use?Proxy vs VPN: what's the difference, and when should you use each?Static vs rotating proxies: how they differ, pros and cons, and when to use eachDedicated vs shared proxies: how they differ, and what "dedicated" means for a 4G proxyIPv4 vs IPv6 proxies: how they differ, why IPv6 proxies are cheap, and when they don't workHow do websites detect proxies? 8 signals anti-bot systems look atProxy glossary A to Z: 35 terms you'll meet when buying and using proxies, explained simplyProxy vs antidetect browser: how they differ, and do you need a proxy if you have antidetect?What is a residential proxy? How it works, pros and cons, and when to use oneWhat is a datacenter proxy? Pros and cons, why it's cheap, and when it's still the right choiceHow to find your IP address on a computer or phone: public IP, local IP, and your IP behind a proxyWhy do you keep getting CAPTCHAs? 9 common triggers, and where your IP fits inreCAPTCHA vs hCaptcha vs Cloudflare Turnstile: how each one decides who gets challengedWhat is botting? Good bots, bad bots, and where your own automation fitsHow to get a Singapore IP address: VPN, proxy, cloud server or SIM, and how to check itProxies for Facebook: managing several accounts more reliably with 4G IPsProxies for TikTok and TikTok Shop: when you need a Singapore IP and how to use it properlyProxies for advertising: checking and managing ads aimed at SingaporeProxies for e-commerce sellers: see marketplaces like a buyer, track competitors, keep store logins steadyProxies for web scraping: which type to choose, how to rotate, and how to play fairDo you need a proxy to buy tickets on ThaiTicketMajor, Ticketmelon or SISTIC?Scraping Google and Bing search results with a proxy, and when to use the API insteadHow to scrape without getting blocked: pace, sessions and clean IPsProxies for price monitoring: tracking competitor and retail prices across regionsScraping anti-bot and anti-proxy websites (Cloudflare, Akamai, DataDome): what works, and the limitsIs web scraping legal? Robots.txt, terms, personal data and copyright (Vietnam, Singapore and beyond)What are 4G proxies used for? 10 jobs mobile proxies do well, and the ones to avoid4G proxies for testing apps and websites as a Singapore mobile user: QA, ads, payments, bot rulesProxies for Instagram: managing brand and client accounts steadily with 4G IPsUsing a proxy to check flight and hotel prices as a Singapore user: when it helps and what to knowResearching the Singapore market with a proxy: see search, ads, marketplaces and competitors as a local userProxies for LinkedIn: managing B2B accounts and reaching the Singapore market the right wayProxies for X (Twitter): managing brand and client accounts steadily and within the rulesProxies for airdrops: why farming wallets through proxies gets disqualified, and how to join airdrops safelyProxies for seeding, bought likes and fake reviews: why they get caught, the risks, and lasting ways to growProxies for flash sales and limited drops: what a proxy can and can't do, and how to shop sales properlyProxies for large-scale, multi-country scraping: choosing proxy types, system design and real costsProxies for Netflix, YouTube and foreign streaming: why they usually fail, cost a lot, and what to do insteadSelling to Singapore from Vietnam: choosing channels, GST, shipping, payments and the tools you needSelling on TikTok Shop Singapore from abroad: seller requirements, workable routes and what a proxy can doThe Singapore online shopping market: who shops, where, how they pay and the big sale seasonsA workflow for agencies managing client accounts with proxies and antidetect: inventory, access, offboardingLocal SEO in Singapore: checking Google and Google Maps rankings as a Singapore user, the right wayProxies for Google Ads: when you need one, the official tools to use first, and the policy lines to knowRoblox lagging, high ping: does a proxy help, and the fixes that really reduce Roblox lagMultiple Roblox accounts (alts): what the rules allow and forbid, whether you need a proxy, and IP bansLag and high ping on Singapore game servers: do proxies or VPNs lower ping, and what actually helpsDiscord proxy: what it can and can't do, how to set it up, and managing communities the right wayShopee and Lazada Singapore proxies: see what Singapore buyers see, run your shop, track competitorsProxies for online business (MMO): which jobs need one, which type to pick and what to avoidProxy for bots and automation: one identity per IP, a polite pace, and what to do when a CAPTCHA appearsHow to set up a proxy on Windows, macOS, iPhone and Android (with a username and password)How to add a proxy to GoLogin, AdsPower, Hidemyacc, GenLogin and MultiloginRotate a proxy IP automatically with an API: curl, Python and Node.js examplesHow to check a proxy: IP, country, carrier, speed and DNS and WebRTC leaksCommon proxy errors and how to fix them: 407, timeouts, ERR_PROXY_CONNECTION_FAILEDScraping JavaScript-rendered sites with a headless browser and a proxy403, 429 and 503 errors when scraping: causes and how to handle them properly (with Python code)Using a proxy with Scrapy: authenticated setup, polite throttling, error fixes and rotating between runsUsing a proxy with curl and wget: HTTP, SOCKS5, authentication, environment variables and debuggingUsing a proxy in Python: requests, httpx and aiohttp with HTTP, SOCKS5 and authenticationSetting up a proxy in Chrome and Edge: a browser-only proxy without changing the whole computerSingapore proxy for Telegram: set up SOCKS5 on desktop, iPhone and Android, and how it differs from MTProtoSlow 4G proxy? How to measure speed and latency properly, and what really makes a proxy fasterUsing proxies safely: protect your proxy password, rotation link, accounts and dataUsing Proxifier for software without proxy support: SOCKS5 setup, per-app rules and DNSRoblox proxies for developers: calling Roblox APIs from HttpService, Open Cloud, and a safe self-hosted relayProtecting your Roblox account: cookie theft, "free Robux", malicious extensions, and how to stay safeHow to set up a proxy in AdsPower: HTTP or SOCKS5, where to paste it, checking the Singapore IP and rotatingHow to add a proxy to GoLogin: HTTP or SOCKS5, where to enter it, checking the Singapore IP and rotatingHow to add a proxy to GenLogin: HTTP or SOCKS5, where to paste it, checking the Singapore IP and rotatingHow to add a proxy to Hidemium: HTTP or SOCKS5, where to enter it, checking the Singapore IP and rotatingHow to add a proxy to BitBrowser: HTTP or SOCKS5, where to enter it, checking the Singapore IP and rotatingCAPTCHA keeps appearing or loops forever: 8 fixes, in the order to try themMobile vs residential vs datacenter proxies: comparing 4G, home and server IPs, and how to chooseSingapore proxies: when you need a Singapore IP and which type to chooseClean proxies and blacklists: what a clean IP means, and why "never blocked" is a myth4G rotating proxies: how mobile IP rotation works, what clean rotation means and how to choose oneHow to tell a real 4G proxy from a fake: check the carrier, IP type, latency and rotationFree vs paid proxies: the real risks of free proxies, and when paying is worth itDedicated 4G proxies, not shared: why a proxy only you use matters, and how to check it yourselfHow many proxies do I need? Working out the number for accounts, teams and scrapingStatic IP proxies for allowlists, APIs and remote access: 5 options and how to choose the right oneVietnam or Singapore proxy? Choosing which country's IP fits your workSingtel, M1 and StarHub proxies: which Singapore carrier a 4G proxy runs on, and how to check itClean proxy and CAPTCHA: how IP reputation decides how many challenges you seeThe real cost of a dirty proxy: CAPTCHAs, retries, wasted bandwidth and blocked accountsSingapore SOCKS5 proxy: when to use it, how to set it up, and how to check it5G proxy vs 4G proxy: what changes, what doesn't, and whether 5G is worth paying more forCheap 4G proxies: $4 gets you 200GB, and how to compare mobile proxy prices properly before you buyRefer a friend and earn 10% on every proxy order: how the 65Proxy referral program worksWhy choose 65Proxy? 8 reasons you can verify, and when you should go elsewhereHow to buy a 4G proxy at 65Proxy: sign up, top up, pay, connect and rotate, step by stepWhere to buy a reliable proxy? 12 things to check before paying any providerTesting a 4G proxy in a 1-hour trial: a minute-by-minute checklistBuy proxies with USDT: paying for a Singapore 4G proxy over TRC20 or BEP20, step by step4G proxy with 500GB: what the plan includes, how far 500GB goes, and how bandwidth is countedGuides to 4G mobile proxies

Using a proxy in Python: requests, httpx and aiohttp with HTTP, SOCKS5 and authentication

Setup and use 3 min read

In this article
  1. 01 requests
  2. 02 httpx
  3. 03 aiohttp
  4. 04 Passwords with special characters
  5. 05 Environment variables
  6. 06 Common errors
  7. 07 Rotating from Python
  8. 08 65Proxy proxies in Python
  9. 09 Frequently asked questions

Python has three popular HTTP libraries (requests, httpx and aiohttp), and each declares a proxy slightly differently. This guide has working sample code for all three, with authenticated HTTP and SOCKS5 proxies, plus the common errors. Every example reads the proxy from a PROXY environment variable in the form http://USER:PASS@HOST:PORT, so the password stays out of your code.

requests

The most familiar library. Pass the proxy through proxies, and use a Session to reuse connections:

Python
import os

import requests

PROXY = os.environ["PROXY"]  # http://USER:PASS@HOST:PORT

session = requests.Session()
session.proxies = {"http": PROXY, "https": PROXY}

resp = session.get("https://api.ipify.org", timeout=30)
print("IP via proxy:", resp.text)

Note: the "https" key in proxies is the kind of site you visit, while the value still starts with http:// because that's how you talk to the proxy.

SOCKS5 with requests

Add SOCKS support with pip install "requests[socks]", then use the socks5h prefix so the proxy resolves domain names:

Python
PROXY = "socks5h://USER:PASS@HOST:PORT"
session.proxies = {"http": PROXY, "https": PROXY}

httpx

httpx offers both sync and async styles. In recent versions, the proxy goes in the proxy argument:

Python
import os

import httpx

with httpx.Client(proxy=os.environ["PROXY"], timeout=30) as client:
    resp = client.get("https://api.ipify.org")
    print("IP via proxy:", resp.text)

The async version:

Python
import asyncio
import os

import httpx


async def main():
    async with httpx.AsyncClient(proxy=os.environ["PROXY"], timeout=30) as client:
        resp = await client.get("https://api.ipify.org")
        print("IP via proxy:", resp.text)


asyncio.run(main())

For SOCKS5, install pip install "httpx[socks]" and use socks5://USER:PASS@HOST:PORT. If an older httpx complains about proxy=, upgrade it: older versions used a different argument name.

aiohttp

aiohttp takes the proxy per request through the proxy argument, and supports HTTP proxies only:

Python
import asyncio
import os

import aiohttp

PROXY = os.environ["PROXY"]  # http://USER:PASS@HOST:PORT


async def main():
    timeout = aiohttp.ClientTimeout(total=30)
    async with aiohttp.ClientSession(timeout=timeout) as session:
        async with session.get("https://api.ipify.org", proxy=PROXY) as resp:
            print("IP via proxy:", await resp.text())


asyncio.run(main())

For SOCKS5 with aiohttp, install the aiohttp-socks library and create the session with its connector. To have aiohttp read the HTTPS_PROXY environment variable, create the session with trust_env=True.

Passwords with special characters

If the username or password contains @, :, / or #, encode it before building the proxy URL:

Python
import os
from urllib.parse import quote

user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASS"], safe="")
PROXY = "http://" + user + ":" + password + "@HOST:PORT"

Without encoding, the library splits the URL wrongly and you get a 407 or a puzzling connection error.

Environment variables

requests and httpx read HTTP_PROXY, HTTPS_PROXY and NO_PROXY automatically when you don't pass a proxy in code:

Terminal
export HTTPS_PROXY="http://USER:PASS@HOST:PORT"
python script.py

Handy for small scripts, but easy to forget: a leftover variable can send other programs through the proxy too. For real projects, declaring the proxy explicitly in code is easier to control.

Common errors

  • 407 Proxy Authentication Required: wrong username or password, or special characters left unencoded.
  • ProxyError / can't connect: wrong host or port, or a SOCKS5 URL without the library's SOCKS support installed.
  • Missing dependencies for SOCKS support: requests without requests[socks].
  • Errors for a few seconds right after rotating: the 4G device is reconnecting; retry shortly.
  • The IP is still your home IP: the proxy isn't on the session you're using, or NO_PROXY excludes that domain.

The full list is in common proxy errors; handling 403 and 429 when scraping is in 403, 429 and 503 errors when scraping.

Rotating from Python

With a 4G proxy, rotating means calling the rotation link (not through the proxy) and waiting until the new IP appears. Full code is in rotating proxy IPs via API. For Scrapy, see using a proxy with Scrapy.

65Proxy proxies in Python

Our 4G proxies offer HTTP and SOCKS5 with a username and password, and work with all three libraries above. Singapore mobile-carrier IPs, a dedicated proxy that isn't shared, rotation by link or API (at most once every 5 minutes), priced 1 day $4, 7 days $13, 1 month $32 (200GB each), plus monthly plans with more bandwidth (500GB $40, 1TB $65). See pricing.

Frequently asked questions

Should I use requests, httpx or aiohttp?

requests for simple scripts; httpx when you want sync and async with the same style; aiohttp when you're already in the asyncio ecosystem. All three work well with proxies.

Should I create a new session after rotating?

Yes. A new session ensures no old connections stay open over the previous IP, and cookies don't carry over from one session to the next.

Can I send many parallel requests through one 4G proxy?

Yes, but they all go out on one IP. Keep parallel connections modest to avoid being limited. See how to scrape without getting blocked.