Telegram Bot SOCKS5 Proxy in Python: aiogram and Telethon
The packages, the exact proxy format for aiogram and Telethon, and how to confirm the traffic really goes through the proxy.
Which library takes the proxy where
A bot written with aiogram talks to the Bot API through aiohttp, so the proxy goes into the aiohttp session. A script written with Telethon speaks Telegram's own protocol and takes the proxy in the client constructor. Both libraries can use a SOCKS5 proxy with a username and password, but each needs its own helper package.
This page is about code. For the Telegram app itself (Desktop, iPhone, Android) see the app setup guide linked here.
Copy host, port, username and password of a SOCKS5 asset from My assets.
Step 2
Test the login with curl (command below). It should return JSON with the proxy's exit IP.
Expected result JSON with an IP that is not yours.
Step 3
Install the helper package for your library: aiohttp-socks for aiogram, python-socks[asyncio] for Telethon.
Step 4
Add the proxy as in the aiogram or Telethon example and run one real call: get_me() for a bot, or the first login for an account.
Step 5
If you want to see the exit IP from Python as well, run the aiohttp check, which uses the same address format as aiogram.
Check the exit IP from Python
# pip install aiohttp aiohttp-socks
import asyncio
import aiohttp
from aiohttp_socks import ProxyConnector
async def main():
connector = ProxyConnector.from_url("socks5://LOGIN:PASSWORD@HOST:PORT") # rdns is on by default for socks5
async with aiohttp.ClientSession(connector=connector) as session:
async with session.get("https://ipinfo.io/json") as response:
print(await response.text()) # the proxy's exit IP, not yours
asyncio.run(main())
Example only: replace HOST, PORT, LOGIN, PASSWORD and the Telegram values with your own.
aiogram bot through SOCKS5
# pip install aiogram aiohttp-socks
import asyncio
from aiogram import Bot
from aiogram.client.session.aiohttp import AiohttpSession
session = AiohttpSession(proxy="socks5://LOGIN:PASSWORD@HOST:PORT")
bot = Bot(token="BOT_TOKEN", session=session)
async def main():
me = await bot.get_me() # a real call to the Bot API, through the proxy
print("Bot:", me.username)
await bot.session.close()
asyncio.run(main())
Example only: replace HOST, PORT, LOGIN, PASSWORD and the Telegram values with your own.
Telethon client through SOCKS5
# pip install telethon "python-socks[asyncio]"
from telethon import TelegramClient
API_ID = 123456 # from my.telegram.org
API_HASH = "YOUR_API_HASH"
proxy = {
"proxy_type": "socks5",
"addr": "HOST",
"port": 3333, # SOCKS5 port; use the PORT from My assets
"username": "LOGIN",
"password": "PASSWORD",
"rdns": True,
}
client = TelegramClient("account1", API_ID, API_HASH, proxy=proxy)
async def main():
me = await client.get_me()
print("Logged in as", me.username)
with client:
client.loop.run_until_complete(main())
Example only: replace HOST, PORT, LOGIN, PASSWORD and the Telegram values with your own.
Example only: replace HOST, PORT, LOGIN, PASSWORD and the Telegram values with your own.
SOCKS5 or HTTP
aiogram's documentation lists http (tunneling), socks4(a) and socks5 as supported, so an HTTP endpoint such as http://LOGIN:PASSWORD@HOST:2222 also works there. For Telethon the examples in its documentation are SOCKS5.
On Proxy302 a static ISP IP is issued with the protocol you chose at purchase, and a per-IP lease also connects over the other protocol on that protocol's port with the same login. A rotating residential login generated as SOCKS5 also works over HTTP on port 2222, but one generated as HTTP does not work over SOCKS5. When in doubt, generate or buy the asset as SOCKS5 and use port 3333.
Check Wrong HOST or PORT, the asset has expired, or the helper package is missing.
Fix Run the curl command. If curl works, check that aiohttp-socks (aiogram) or python-socks (Telethon) is installed in the same environment as the bot.
Stop when If curl also times out, stop changing code: check host, port and the asset's status in My assets.
Authentication failed or the proxy refuses the connection
Check Typo in LOGIN or PASSWORD, or special characters in the password break the URL.
Fix Copy the values again. In the URL form, percent-encode characters such as @, : and / in the password; in the Telethon dict, write the password as is.
curl works but the bot shows your own IP
Check The proxy was not passed to the session that sends the requests, for example a second Bot object is created without it.
Fix Create one session with the proxy and pass it to every Bot you create.
Works for a while, then the exit changes
Check A rotating residential login gives a new IP on a new connection.
Fix Use a static IP for a bot or account that should keep one address.
How to do it with Proxy302
A bot or a Telegram account that should keep one address fits a static ISP IP bought as SOCKS5: it does not rotate during the lease, costs US$0.50 for 1 day or US$7.99 for 30 days (about US$0.27 a day), and SOCKS5 runs on port 3333 of proxy.proxy302.com. Several bots can each get their own IP; up to 100 can be bought in one order.
There is no free trial; the smallest purchase is one IP for one day. The Telegram page has the app setup and the use-case overview.
Telegram proxy on your own static ISP IP: SOCKS5 with a username and password goes straight into Telegram's built-in proxy settings, for accounts, channels and bots.
SOCKS5 on all three lines: rotating residential from US$1.50/GB, static ISP and datacenter IPs per IP and term. Port 3333 with username and password, and the errors you see when a setting is wrong.
Check the exit IP, country and ISP your proxy really gives you in 30 seconds — and why IP databases disagree on the city. With our own test of three lookup services.
Read on 13 November 2026: to use a proxy with AiohttpSession install aiohttp-socks; supported protocols are http (tunneling), socks4(a) and socks5; usage is AiohttpSession(proxy="protocol://host:port/") passed to Bot(token, session=session).
Read on 13 November 2026: install python-socks[asyncio]; pass proxy= to TelegramClient; for SOCKS5 a dict with proxy_type, addr and port, optional username, password and rdns.
Read on 13 November 2026: ProxyConnector.from_url("socks5://user:[email protected]:1080"); remote DNS (rdns) is the default for socks5; installed as aiohttp_socks.
Proxy302 product facts and price list
Product observation · Confirmed on:
Product facts file, checked on 13 November 2026 against the console, backend and price list: static ISP lease prices per IP (US$, 1 PTC = US$1), rotating residential Budget line price per GB, HTTP port 2222 and SOCKS5 port 3333 on proxy.proxy302.com, which protocols work for which product, no free trial.
Ready to try it?
Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.