2018-01-05 02:59:53 +03:00
|
|
|
============
|
|
|
|
Test Servers
|
|
|
|
============
|
|
|
|
|
|
|
|
|
|
|
|
To run Telethon on a test server, use the following code:
|
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
.. code-block:: python
|
2018-01-05 02:59:53 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
client = TelegramClient(None, api_id, api_hash)
|
|
|
|
client.session.set_dc(dc_id, '149.154.167.40', 80)
|
2018-01-05 02:59:53 +03:00
|
|
|
|
|
|
|
You can check your ``'test ip'`` on https://my.telegram.org.
|
|
|
|
|
2019-07-06 13:10:25 +03:00
|
|
|
You should set `None` session so to ensure you're generating a new
|
2018-01-05 02:59:53 +03:00
|
|
|
authorization key for it (it would fail if you used a session where you
|
|
|
|
had previously connected to another data center).
|
|
|
|
|
2018-03-15 11:29:54 +03:00
|
|
|
Note that port 443 might not work, so you can try with 80 instead.
|
|
|
|
|
|
|
|
Once you're connected, you'll likely be asked to either sign in or sign up.
|
|
|
|
Remember `anyone can access the phone you
|
2018-01-05 02:59:53 +03:00
|
|
|
choose <https://core.telegram.org/api/datacenter#testing-redirects>`__,
|
2018-03-15 11:29:54 +03:00
|
|
|
so don't store sensitive data here.
|
2018-01-05 02:59:53 +03:00
|
|
|
|
2018-03-15 11:29:54 +03:00
|
|
|
Valid phone numbers are ``99966XYYYY``, where ``X`` is the ``dc_id`` and
|
|
|
|
``YYYY`` is any number you want, for example, ``1234`` in ``dc_id = 2`` would
|
|
|
|
be ``9996621234``. The code sent by Telegram will be ``dc_id`` repeated five
|
|
|
|
times, in this case, ``22222`` so we can hardcode that:
|
2018-01-05 02:59:53 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
.. code-block:: python
|
2018-01-05 02:59:53 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
client = TelegramClient(None, api_id, api_hash)
|
|
|
|
client.session.set_dc(2, '149.154.167.40', 80)
|
2018-07-09 21:54:43 +03:00
|
|
|
client.start(
|
2018-06-22 15:44:59 +03:00
|
|
|
phone='9996621234', code_callback=lambda: '22222'
|
2018-07-09 21:54:43 +03:00
|
|
|
)
|