mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-21 17:06:36 +03:00
Move creating a client to Examples
parent
77592cb125
commit
722348fb50
37
Home.md
37
Home.md
|
@ -9,45 +9,8 @@ TimeoutError: The read operation exceeded the timeout.
|
|||
|
||||
Please check this out before opening an issue. Thanks to [issue 172](https://github.com/LonamiWebs/Telethon/issues/172) for the debug level log.
|
||||
|
||||
All examples shown here assume that you've successfully created a client as follows:
|
||||
```python
|
||||
from telethon import TelegramClient
|
||||
|
||||
# Use your own values here
|
||||
api_id = 12345
|
||||
api_hash = '0123456789abcdef0123456789abcdef'
|
||||
phone_number = '+34600000000'
|
||||
|
||||
client = TelegramClient('some_name', api_id, api_hash)
|
||||
client.connect() # Must return True, otherwise, try again
|
||||
|
||||
if not client.is_user_authorized():
|
||||
client.send_code_request(phone_number)
|
||||
client.sign_in(phone_number, input('Enter code: '))
|
||||
|
||||
# The `client´ is now ready
|
||||
```
|
||||
|
||||
The online documentation for all available requests, types and constructors is available online at https://lonamiwebs.github.io/Telethon/.
|
||||
|
||||
Although Python will probably clean up the resources used by the `TelegramClient`, you should always `.disconnect()` it once you're done:
|
||||
|
||||
```python
|
||||
client.disconnect()
|
||||
```
|
||||
|
||||
If you get a `PhoneNumberUnoccupiedError` while calling `.sign_in()`, this is because you don't have a Telegram account yet! In this case, use `.sign_up()` instead.
|
||||
|
||||
## Side notes
|
||||
|
||||
As a side note, you may come across, or find useful, these lines:
|
||||
```python
|
||||
from telethon.utils import xyz
|
||||
from telethon.helpers import zyx
|
||||
```
|
||||
|
||||
The first one `utils` are only utilities, which are not related per se to the Telegram API. On the other hand, the `helpers` are indeed helpers to work with the Telegram API, and to make some tasks less cumbersome. You can always call `help(utils)` or `help(helpers)` once you import them to see what goodies it contains.
|
||||
|
||||
## Possible problems
|
||||
|
||||
If you ever receive a `PEER_FLOOD` error or aren't able to perform certain requests, it might mean that your account is limited, and there's not much Telethon can do about this. Talk to [@SpamBot](https://t.me/SpamBot) for more information, or refer to the [spam FAQ](https://www.telegram.org/faq_spam).
|
Loading…
Reference in New Issue
Block a user