Skip to content

Network Configuration and Proxy

Eana Hufwe edited this page Feb 10, 2019 · 4 revisions

Written for EFB Telegram Master 2.0.0b18

Network configuration: timeout tweaks

This chapter is adopted from Python Telegram Bot wiki, licensed under CC-BY 3.0.

ptb performs HTTPS requests using urllib3. urllib3 provides control over connect_timeout & read_timeout. urllib3 does not separate between what would be considered read & write timeout, so read_timeout serves for both. The defaults chosen for each of these parameters is 5 seconds.

The read_timeout is overwritten to 20 seconds when using send methods which attach files (send_audio, send_document, etc.). When sending big files, calling Bot.send_*(timeout=BIGGER_VALUE) might be a good idea.

The connect_timeout value controls the timeout for establishing a connection to the Telegram server(s).

Changing the defaults of read_timeout & connet_timeout can be done by adjusting values request_kwargs section in ETM's config.yaml.

# ...
request_kwargs:
    read_timeout: 6
    connect_timeout: 7

Run ETM behind a proxy

This chapter is adopted from Python Telegram Bot wiki, licensed under CC-BY 3.0.

You can appoint proxy specifically for ETM without affecting other channels running in together in the same EFB instance. This can also be done by adjusting values request_kwargs section in ETM's config.yaml.

HTTP proxy server

request_kwargs:
    # ...
    proxy_url: http://PROXY_HOST:PROXY_PORT/
    # Optional, if you need authentication:
    username: PROXY_USER
    password: PROXY_PASS 

Socks5 proxy server

This is configuration is supported, but requires an optional/extra python package. To install:

pip install python-telegram-bot[socks]
request_kwargs:
    # ...
    proxy_url: socks5://URL_OF_THE_PROXY_SERVER:PROXY_PORT
    # Optional, if you need authentication:
    urllib3_proxy_kwargs: 
        username: PROXY_USER
        password: PROXY_PASS
Clone this wiki locally