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