Skip to content

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.

aiogram and Telethon side by side

aiogram and Telethon side by side
Itemaiogram (bots)Telethon (accounts and bots)
Installpip install aiogram aiohttp-sockspip install telethon "python-socks[asyncio]"
Where the proxy goesAiohttpSession(proxy=...), then Bot(token, session=session)TelegramClient(..., proxy=...)
FormatA URL: socks5://LOGIN:PASSWORD@HOST:PORTA dict: proxy_type, addr, port, optional username, password, rdns
Other protocolshttp (tunneling), socks4(a), socks5Documented here for SOCKS5; MTProto proxies use a different format

Source: aiogram and Telethon documentation and the aiohttp-socks project page, read on 13 November 2026.

Setup in 5 steps

  1. Step 1

    Copy host, port, username and password of a SOCKS5 asset from My assets.

  2. 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.

  3. Step 3

    Install the helper package for your library: aiohttp-socks for aiogram, python-socks[asyncio] for Telethon.

  4. 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.

  5. 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.

Test the login with curl first

curl -x socks5h://LOGIN:PASSWORD@HOST:PORT https://ipinfo.io/json

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.

When the bot does not connect

The bot hangs and then times out

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.

Steps in Proxy302

  1. Step 1

    Open the static ISP page, choose the country and SOCKS5, review the cost and pay from the wallet.

  2. Step 2

    Open My assets and copy host, port, username and password.

  3. Step 3

    Put them into the proxy URL (aiogram) or dict (Telethon) from the examples.

  4. Step 4

    Run the check and then the bot; confirm the exit with https://ipinfo.io/json.

Telegram bot proxy FAQ

How do I use a SOCKS5 proxy with aiogram?

Install aiohttp-socks, create AiohttpSession(proxy="socks5://LOGIN:PASSWORD@HOST:PORT") and pass it to Bot(token, session=session).

How do I use a SOCKS5 proxy with Telethon?

Install python-socks[asyncio] and pass proxy={"proxy_type": "socks5", "addr": "HOST", "port": 3333, "username": "LOGIN", "password": "PASSWORD"} to TelegramClient.

Does the proxy have to support a username and password?

Both libraries can send one. Use the credentials from My assets; for a proxy without a login, leave them out.

Why does my bot ignore the proxy?

The usual cause is a missing helper package, or the proxy was passed to a different session or client than the one making the requests.

How do I check that the bot uses the proxy?

Test the login with curl, run the aiohttp check with the same address, then call get_me() and watch for the exit IP on ipinfo.io.

Reference links

4
  1. aiogram documentation: AiohttpSession

    Official documentation · Confirmed on:

    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).

  2. Telethon documentation: signing in, proxies

    Official documentation · Confirmed on:

    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.

  3. aiohttp-socks on GitHub

    Official documentation · Confirmed on:

    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.

  4. 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.