aiohttp¶
AiohttpSession represents a wrapper-class around ClientSession from aiohttp
Currently AiohttpSession is a default session used in aiogram.Bot
- class aiogram.client.session.aiohttp.AiohttpSession(proxy: Iterable[str | Tuple[str, BasicAuth]] | str | Tuple[str, BasicAuth] | None = None, limit: int = 100, **kwargs: Any)[source]¶
Usage example¶
from aiogram import Bot
from aiogram.client.session.aiohttp import AiohttpSession
session = AiohttpSession()
bot = Bot('42:token', session=session)
Proxy requests in AiohttpSession¶
In order to use AiohttpSession with proxy connector you have to install aiohttp-socks
Binding session to bot:
from aiogram import Bot
from aiogram.client.session.aiohttp import AiohttpSession
session = AiohttpSession(proxy="protocol://host:port/")
bot = Bot(token="bot token", session=session)
Note
Only following protocols are supported: http(tunneling), socks4(a), socks5 as aiohttp_socks documentation claims.
Proxy chains¶
Since aiohttp-socks supports proxy chains, you’re able to use them in aiogram
Example of chain proxies:
from aiohttp import BasicAuth
from aiogram.client.session.aiohttp import AiohttpSession
auth = BasicAuth(login="user", password="password")
session = AiohttpSession(
proxy={
"protocol0://host0:port0",
"protocol1://user:password@host1:port1",
("protocol2://host2:port2", auth),
} # can be any iterable if not set
)