Hide navigation sidebar
Hide table of contents sidebar
PTB has undergone significant changes in v20. Please read the documentation carefully and also check out the transition guide in the wiki.
Back to top
Toggle table of contents sidebar

# 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, http_version='1.1', socket_options=None, proxy=None)

  Bases: `telegram.request.BaseRequest`

  Implementation of `BaseRequest` using the library httpx.

  Use In

  - `telegram.ext.ApplicationBuilder.get_updates_request()`

  - `telegram.ext.ApplicationBuilder.request()`

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

    - proxy_url (`str`, optional) –

      Legacy name for `proxy`, kept for backward compatibility. Defaults to `None`.

      Deprecated since version 20.7.

    - 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 to `do_request()`. Defaults to `5`.

    - 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 to `do_request()`. Defaults to `5`.

    - 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 to `do_request()`. Defaults to `5`.

    - 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 to `1`.

      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!

    - http_version (`str`, optional) –

      If `"2"` or `"2.0"`, HTTP/2 will be used instead of HTTP/1.1. Defaults to `"1.1"`.

      New in version 20.1.

      Changed in version 20.2: Reset the default version to 1.1.

      Changed in version 20.5: Accept `"2"` as a valid value.

    - socket_options (Collection[`tuple`], optional) –

      Socket options to be passed to the underlying library.

      Note

      The values accepted by this parameter depend on the operating system. This is a low-level parameter and should only be used if you are familiar with these concepts.

      New in version 20.7.

    - proxy (`str` | `httpx.Proxy` | `httpx.URL`, optional) –

      The URL to a proxy server, a `httpx.Proxy` object or a `httpx.URL` object. For example `'http://127.0.0.1:3128'` or `'socks5://127.0.0.1:3128'`. Defaults to `None`.

      Note

      - The proxy URL can also be set via the environment variables `HTTPS_PROXY` or `ALL_PROXY`. See the docs of httpx for more info.

      - HTTPS proxies can be configured by passing a `httpx.Proxy` object with a corresponding `ssl_context`.

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

      New in version 20.7.

  async do_request(url, method, request_data=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None)

    See `BaseRequest.do_request()`.

  property http_version

    Used HTTP version, see `http_version`.

    New in version 20.2.

    Type:

      `str`

  async initialize()

    See `BaseRequest.initialize()`.

  property read_timeout

    See `BaseRequest.read_timeout`.

    Returns:

      The default read timeout in seconds as passed to

        `HTTPXRequest.read_timeout`.

    Return type:

      `float` | `None`

  async shutdown()

    See `BaseRequest.shutdown()`.