Update proxy docs and warn if python-socks is not installed

As suggested in #4505.
This commit is contained in:
Lonami Exo
2025-12-30 11:18:49 +01:00
parent 05b8488858
commit 5efa1fe2ed
6 changed files with 20 additions and 51 deletions

View File

@@ -117,43 +117,14 @@ Signing In behind a Proxy
=========================
If you need to use a proxy to access Telegram,
you will need to either:
* For Python >= 3.6 : `install python-socks[asyncio]`__
* For Python <= 3.5 : `install PySocks`__
and then change
you will need to `install python-socks[asyncio]`__
and then pass a proxy argument to the client:
.. code-block:: python
TelegramClient('anon', api_id, api_hash)
TelegramClient('anon', api_id, api_hash, proxy=...)
with
.. code-block:: python
TelegramClient('anon', api_id, api_hash, proxy=("socks5", '127.0.0.1', 4444))
(of course, replacing the protocol, IP and port with the protocol, IP and port of the proxy).
The ``proxy=`` argument should be a dict (or tuple, for backwards compatibility),
consisting of parameters described `in PySocks usage`__.
The allowed values for the argument ``proxy_type`` are:
* For Python <= 3.5:
* ``socks.SOCKS5`` or ``'socks5'``
* ``socks.SOCKS4`` or ``'socks4'``
* ``socks.HTTP`` or ``'http'``
* For Python >= 3.6:
* All of the above
* ``python_socks.ProxyType.SOCKS5``
* ``python_socks.ProxyType.SOCKS4``
* ``python_socks.ProxyType.HTTP``
Example:
The ``proxy=`` argument should be a dict with the following properties:
.. code-block:: python
@@ -166,16 +137,9 @@ Example:
'rdns': True # (optional) whether to use remote or local resolve, default remote
}
For backwards compatibility with ``PySocks`` the following format
is possible (but discouraged):
.. code-block:: python
proxy = (socks.SOCKS5, '1.1.1.1', 5555, True, 'foo', 'bar')
A warning will be emitted if the proxy is specified but ``python-socks`` is not installed.
.. __: https://github.com/romis2012/python-socks#installation
.. __: https://github.com/Anorov/PySocks#installation
.. __: https://github.com/Anorov/PySocks#usage-1
Using MTProto Proxies