telegram.request.HTTPXRequest#
- class telegram.request.HTTPXRequest(connection_pool_size=1, proxy_url=None, read_timeout=5.0, write_timeout=5.0, connect_timeout=5.0, pool_timeout=1.0)[source]#
Bases:
telegram.request.BaseRequest
Implementation of
BaseRequest
using the library httpx.New in version 20.0.
- Parameters
connection_pool_size (
int
, optional) –Number of connections to keep in the connection pool. Defaults to
1
.Note
Independent of the value, one additional connection will be reserved for
telegram.Bot.get_updates()
.The URL to the proxy server. For example
'http://127.0.0.1:3128'
or'socks5://127.0.0.1:3128'
. Defaults toNone
.Note
The proxy URL can also be set via the environment variables
HTTPS_PROXY
orALL_PROXY
. See the docs of httpx for more info.For Socks5 support, additional dependencies are required. Make sure to install PTB via pip install python-telegram-bot[socks] in this case.
Socks5 proxies can not be set via environment variables.
read_timeout (
float
|None
, optional) – If passed, specifies the maximum amount of time (in seconds) to wait for a response from Telegram’s server. This value is used unless a different value is passed todo_request()
. Defaults to5
.write_timeout (
float
|None
, optional) – If passed, specifies the maximum amount of time (in seconds) to wait for a write operation to complete (in terms of a network socket; i.e. POSTing a request or uploading a file). This value is used unless a different value is passed todo_request()
. Defaults to5
.connect_timeout (
float
|None
, optional) – If passed, specifies the maximum amount of time (in seconds) to wait for a connection attempt to a server to succeed. This value is used unless a different value is passed todo_request()
. Defaults to5
.pool_timeout (
float
|None
, optional) –If passed, specifies the maximum amount of time (in seconds) to wait for a connection to become available. This value is used unless a different value is passed to
do_request()
. Defaults to1
.Warning
With a finite pool timeout, you must expect
telegram.error.TimedOut
exceptions to be thrown when more requests are made simultaneously than there are connections in the connection pool!
- async do_request(url, method, request_data=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None)[source]#