Skip to content

Get TTL Expire when using together with proxy #4806

Closed as not planned
Closed as not planned
@Letri51hn

Description

@Letri51hn

Steps to Reproduce

  1. I have a running bot. But recently my country blocked telegram so i have to use proxy for anything related to Telegram
  2. This code piece without proxy run smoothly
def main():
    SOCKS5_PROXY_URL = <working_proxyURL>
    # Create httpx proxy object
    proxy = httpx.Proxy(SOCKS5_PROXY_URL)

    app = ApplicationBuilder().proxy(proxy).get_updates_proxy(proxy).token(<valid_token>).build()
    app.post_init = set_commands
    app.add_handler(CommandHandler("start", start))
    app.add_handler(CallbackQueryHandler(button_handler))
    app.run_polling()

Expected behaviour

Using the bot over socks5 proxy

Actual behaviour

Problem at app.run_polling() with exception: telegram.error.NetworkError: httpx.ProxyError: Proxy Server could not connect: TTL expired.

More information:

Exception has occurred: NetworkError
httpx.ProxyError: Proxy Server could not connect: TTL expired.
httpcore.ProxyError: Proxy Server could not connect: TTL expired.

The above exception was the direct cause of the following exception:

httpx.ProxyError: Proxy Server could not connect: TTL expired.

The above exception was the direct cause of the following exception:

  File "D:\Workspace\CheckinBot\bot - Copy.py", line 157, in main
    app.run_polling()
    ~~~~~~~~~~~~~~~^^
  File "D:\Workspace\CheckinBot\bot - Copy.py", line 162, in <module>
    main()
    ~~~~^^
telegram.error.NetworkError: httpx.ProxyError: Proxy Server could not connect: TTL expired.

Operating System

Windows 11 Pro

Version of Python, python-telegram-bot & dependencies

python-telegram-bot 22.1
Bot API 9.0
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr  8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]

Relevant log output

PS D:\Workspace\CheckinBot>  d:; cd 'd:\Workspace\CheckinBot'; & 'c:\Users\vitco\AppData\Local\Programs\Python\Python313\python.exe' 'c:\Users\vitco\.vscode\extensions\ms-python.debugpy-2025.8.0-win32-x64\bundled\libs\debugpy\launcher' '58855' '--' 'd:\Workspace\CheckinBot\bot - Copy.py' 
Network Retry Loop (Bootstrap Initialize Application): Failed run number 0 of 0. Aborting.
Traceback (most recent call last):
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_transports\default.py", line 101, in map_httpcore_exceptions
    yield
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_transports\default.py", line 394, in handle_async_request
    resp = await self._pool.handle_async_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpcore\_async\connection_pool.py", line 256, in handle_async_request
    raise exc from None
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpcore\_async\connection_pool.py", line 236, in handle_async_request
    response = await connection.handle_async_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        pool_request.request
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpcore\_async\socks_proxy.py", line 295, in handle_async_request
    raise exc
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpcore\_async\socks_proxy.py", line 244, in handle_async_request
    await _init_socks5_connection(**kwargs)
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpcore\_async\socks_proxy.py", line 102, in _init_socks5_connection
    raise ProxyError(f"Proxy Server could not connect: {reply_code}.")
httpcore.ProxyError: Proxy Server could not connect: TTL expired.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\request\_httpxrequest.py", line 277, in do_request
    res = await self._client.request(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_client.py", line 1540, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_client.py", line 1629, in send
    response = await self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_client.py", line 1657, in _send_handling_auth
    response = await self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_client.py", line 1694, in _send_handling_redirects
    response = await self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_client.py", line 1730, in _send_single_request
    response = await transport.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_transports\default.py", line 393, in handle_async_request
    with map_httpcore_exceptions():
         ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\contextlib.py", line 162, in __exit__
    self.gen.throw(value)
    ~~~~~~~~~~~~~~^^^^^^^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\httpx\_transports\default.py", line 118, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ProxyError: Proxy Server could not connect: TTL expired.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\ext\_utils\networkloop.py", line 115, in network_retry_loop
    if not await do_action():
           ^^^^^^^^^^^^^^^^^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\ext\_utils\networkloop.py", line 93, in do_action
    return await action_cb()
           ^^^^^^^^^^^^^^^^^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\ext\_application.py", line 486, in initialize
    await self.bot.initialize()
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\ext\_extbot.py", line 308, in initialize
    await super().initialize()
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\_bot.py", line 835, in initialize
    await self.get_me()
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\ext\_extbot.py", line 1969, in get_me
    return await super().get_me(
           ^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\_bot.py", line 967, in get_me
    result = await self._post(
             ^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\_bot.py", line 691, in _post
    return await self._do_post(
           ^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\ext\_extbot.py", line 362, in _do_post
    return await super()._do_post(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\_bot.py", line 720, in _do_post
    result = await request.post(
             ^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\request\_baserequest.py", line 197, in post
    result = await self._request_wrapper(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\request\_baserequest.py", line 304, in _request_wrapper
    code, payload = await self.do_request(
                    ^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "c:\Users\vitco\AppData\Local\Programs\Python\Python313\Lib\site-packages\telegram\request\_httpxrequest.py", line 301, in do_request
    raise NetworkError(f"httpx.{err.__class__.__name__}: {err}") from err
telegram.error.NetworkError: httpx.ProxyError: Proxy Server could not connect: TTL expired.

Additional Context

Proxy url is working for sure. I can verify it by using HTTPX to send request over it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions