python-telegram-bot/python-telegram-bot · error · RuntimeError

_TWO_ARGS_REQ.format(name, "http_version")

Error message

_TWO_ARGS_REQ.format(name, "http_version")

What it means

Raised when builder.http_version(...) was set and you subsequently call request()/get_updates_request() with a Request instance. HTTP version selection and a custom Request cannot both be applied.

Source

Thrown at src/telegram/ext/_applicationbuilder.py:459

            timeouts.append("media_write_timeout")

        # Code below tests if it's okay to set a Request object. Only okay if no other request args
        # or instances containing a Request were set previously
        for attr in timeouts:
            if not isinstance(getattr(self, f"_{prefix}{attr}"), DefaultValue):
                raise RuntimeError(_TWO_ARGS_REQ.format(name, attr))

        if not isinstance(getattr(self, f"_{prefix}connection_pool_size"), DefaultValue):
            raise RuntimeError(_TWO_ARGS_REQ.format(name, "connection_pool_size"))

        if not isinstance(getattr(self, f"_{prefix}proxy"), DefaultValue):
            raise RuntimeError(_TWO_ARGS_REQ.format(name, "proxy"))

        if not isinstance(getattr(self, f"_{prefix}socket_options"), DefaultValue):
            raise RuntimeError(_TWO_ARGS_REQ.format(name, "socket_options"))

        if not isinstance(getattr(self, f"_{prefix}http_version"), DefaultValue):
            raise RuntimeError(_TWO_ARGS_REQ.format(name, "http_version"))

        self._bot_check(name)

        if self._updater not in (DEFAULT_NONE, None):
            raise RuntimeError(_TWO_ARGS_REQ.format(name, "updater instance"))

    def _request_param_check(self, name: str, get_updates: bool) -> None:
        if get_updates and self._get_updates_request is not DEFAULT_NONE:
            raise RuntimeError(  # disallow request args for get_updates if Request for that is set
                _TWO_ARGS_REQ.format(f"get_updates_{name}", "get_updates_request instance")
            )
        if self._request is not DEFAULT_NONE:  # disallow request args if request is set
            raise RuntimeError(_TWO_ARGS_REQ.format(name, "request instance"))

        if self._bot is not DEFAULT_NONE:  # disallow request args if bot is set (has Request)
            raise RuntimeError(
                _TWO_ARGS_REQ.format(
                    f"get_updates_{name}" if get_updates else name, "bot instance"

View on GitHub (pinned to d3b69d2e9f)

Solutions

  1. Set http_version on the Request instance (HTTPXRequest(http_version='2')) and remove builder.http_version()
  2. Or keep http_version() and avoid request()

Example fix

# before
ApplicationBuilder().token(T).http_version('2').request(HTTPXRequest())
# after
ApplicationBuilder().token(T).request(HTTPXRequest(http_version='2'))
Defensive patterns

Strategy: validation

Validate before calling

HTTPXRequest(http_version='2')  # requires the httpx[http2] extra

Prevention

When it happens

Trigger: builder.http_version('2') followed by builder.request(...) or builder.get_updates_request(...).

Common situations: Enabling HTTP/2, then adding a custom Request for other tuning; common after upgrading to v20+ where these methods became exclusive.

Related errors


AI-assisted analysis of python-telegram-bot/python-telegram-bot@d3b69d2e9f (2026-08-28). Data as JSON: /api/errors/50b2ace7ec5b0e0f. Report an issue: GitHub.