Приведенный здесь код представляет собой пример кода, предложенный в официальном руководстве.
Код: Выделить всё
# Use your own values from my.telegram.org
api_id = ***
api_hash = '***'
# The first parameter is the .session file name (absolute paths allowed)
async with TelegramClient('new_session', api_id, api_hash) as client:
client.loop.run_until_complete(client.send_message('me', 'Hello, myself!'))
client.run_until_disconnected()
Код: Выделить всё
Please enter your phone (or bot token):
---------------------------------------------------------------------------
AuthKeyUnregisteredError Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/telethon/client/users.py in is_user_authorized(self)
190 # Any request that requires authorization will work
--> 191 await self(functions.updates.GetStateRequest())
192 self._authorized = True
Код: Выделить всё
AuthKeyUnregisteredError: The key is not registered in the system (caused by GetStateRequest)
During handling of the above exception, another exception occurred:
EOFError Traceback (most recent call last)
in async-def-wrapper()
7 client.loop.run_until_complete(client.send_message('me', 'Hello, myself!'))
8 client.run_until_disconnected()
----> 9
/usr/local/lib/python3.7/site-packages/telethon/client/auth.py in __aenter__(self)
634
635 async def __aenter__(self):
--> 636 return await self.start()
637
638 async def __aexit__(self, *args):
/usr/local/lib/python3.7/site-packages/telethon/client/auth.py in _start(self, phone, password, bot_token, force_sms, code_callback, first_name, last_name, max_attempts)
145 # Turn the callable into a valid phone number (or bot token)
146 while callable(phone):
--> 147 value = phone()
148 if inspect.isawaitable(value):
149 value = await value
/usr/local/lib/python3.7/site-packages/telethon/client/auth.py in ()
18 def start(
19 self: 'TelegramClient',
---> 20 phone: typing.Callable[[], str] = lambda: input('Please enter your phone (or bot token): '),
21 password: typing.Callable[[], str] = lambda: getpass.getpass('Please enter your password: '),
22 *,
EOFError: EOF when reading a line
Код: Выделить всё
The key is not registered in the system (caused by GetStateRequest)
Подробнее здесь: https://stackoverflow.com/questions/623 ... h-telethon
Мобильная версия