因此,我正在为Pythonm学习电传图书馆,但在乞讨过程中,我遇到了一个错误:
/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运行以下代码:
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())我已经阅读了这个模块的基本文档,但是我无法找到正确的解决方案。拜托,伙计们,帮帮我
谢谢。
发布于 2022-09-27 14:24:54
您需要使用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()在v1中是特殊的,不需要await,但是通常情况下,最好是在async def中编写所有代码,而不是依赖于这种魔力。
https://stackoverflow.com/questions/73763938
复制相似问题