Issue
This Content is from Stack Overflow. Question asked by Stanford Martinez
So I am learning the telethon library for Pythonm but right in the beggining I’ve ran into the error:
/Users/user1/Desktop/TelegramBot/main.py:8: RuntimeWarning: coroutine 'UserMethods.get_me' was never awaited
print(client.get_me())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Running the following code:
import decouple
from telethon import TelegramClient
client = TelegramClient('testSesh', decouple.config('API_ID_TEST'), decouple.config('API_HASH_TEST'))
client.start()
print(client.get_me())
I have read the basic documentation for this module but I wasn’t able to find the correct solution. Please, guys, help me :/
Thank you.
Solution
You need to use await
:
import decouple
from telethon import TelegramClient
client = TelegramClient('testSesh', decouple.config('API_ID_TEST'), decouple.config('API_HASH_TEST'))
async def main():
await client.start()
print(await client.get_me())
client.loop.run_until_complete(main())
start()
is special-cased in v1 to not need the await
but it’s generally better if you write all your code inside an async def
and not rely on this magic.
This Question was asked in StackOverflow by Stanford Martinez and Answered by Lonami It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.