mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Document MTProto Proxy usage (#1205)
This commit is contained in:
parent
8d28d1145a
commit
d61bb2e87f
|
@ -126,3 +126,54 @@ consisting of parameters described `in PySocks usage`__.
|
||||||
|
|
||||||
.. __: https://github.com/Anorov/PySocks#installation
|
.. __: https://github.com/Anorov/PySocks#installation
|
||||||
.. __: https://github.com/Anorov/PySocks#usage-1
|
.. __: https://github.com/Anorov/PySocks#usage-1
|
||||||
|
|
||||||
|
|
||||||
|
Using MTProto Proxies
|
||||||
|
=====================
|
||||||
|
|
||||||
|
MTProto Proxies are Telegram's alternative to normal proxies,
|
||||||
|
and work a bit differently. The following protocols are available:
|
||||||
|
|
||||||
|
* ``ConnectionTcpMTProxyAbridged``
|
||||||
|
* ``ConnectionTcpMTProxyIntermediate``
|
||||||
|
* ``ConnectionTcpMTProxyRandomizedIntermediate`` (preferred)
|
||||||
|
|
||||||
|
For now, you need to manually specify these special connection modes
|
||||||
|
if you want to use a MTProto Proxy. Your code would look like this:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from telethon import TelegramClient, connection
|
||||||
|
# we need to change the connection ^^^^^^^^^^
|
||||||
|
|
||||||
|
client = TelegramClient(
|
||||||
|
'anon',
|
||||||
|
api_id,
|
||||||
|
api_hash,
|
||||||
|
|
||||||
|
# Use one of the available connection modes.
|
||||||
|
# Normally, this one works with most proxies.
|
||||||
|
connection=connection.ConnectionTcpMTProxyRandomizedIntermediate,
|
||||||
|
|
||||||
|
# Then, pass the proxy details as a tuple:
|
||||||
|
# (host name, port, proxy secret)
|
||||||
|
#
|
||||||
|
# If the proxy has no secret, the secret must be:
|
||||||
|
# '00000000000000000000000000000000'
|
||||||
|
proxy=('mtproxy.example.com', 2002, 'secret')
|
||||||
|
)
|
||||||
|
|
||||||
|
In future updates, we may make it easier to use MTProto Proxies
|
||||||
|
(such as avoiding the need to manually pass ``connection=``).
|
||||||
|
|
||||||
|
In short, the same code above but without comments to make it clearer:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from telethon import TelegramClient, connection
|
||||||
|
|
||||||
|
client = TelegramClient(
|
||||||
|
'anon', api_id, api_hash,
|
||||||
|
connection=connection.ConnectionTcpMTProxyRandomizedIntermediate,
|
||||||
|
proxy=('mtproxy.example.com', 2002, 'secret')
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user