How to configure Proxy in Aiogram 3.1.1 (Python)

530 views Asked by At
import asyncio

from aiogram import Dispatcher, Bot
from aiogram.filters import CommandStart
from aiogram.types import Message

token = 'tokentokentokentokentokentokentoken'
the_bot = Bot(token)
main_handler = Dispatcher()

@main_handler.message(CommandStart())
async def cmd_start(msg: Message) -> None:
    await msg.answer('hi')

async def main():
    await main_handler.start_polling(the_bot)
if __name__ == '__main__':
    asyncio.run(main())

getting this error

Running a Telegram bot off of my own computer. I live in Xi'An China so I can't get to the API because Telegram is blocked here. wath do?

2

There are 2 answers

1
Masim207 On

Aiogram 3.1.1 didnot natively support proxy configuration, to use proxy for, you typically needed to use external Python libraries like aiosocksy or aiohttp. These libraries can be used to route your bot requests through a proxy server.

0
Asilbek Tolibov On

you can write like this

from aiogram import Bot
from aiogram.client.session.aiohttp import AiohttpSession

session = AiohttpSession(proxy="protocol://host:port/")
bot = Bot(token="bot token", session=session)