Python Telegram Bot在Windows2019服务器出现RuntimeWarning求助
问题:Telegram Bot测试代码在Windows 11正常运行,Windows 2019服务器报协程未等待警告
我编写了一段Python代码用于测试Telegram Bot功能,在Windows 11笔记本上运行完全正常,但在Windows 2019服务器上运行时,出现以下输出:
c:\Python\Scripts\telegram_test.py:11: RuntimeWarning: coroutine 'Bot.send_message' was never awaited bot.sendMessage(chat_id=chat_id, text=msg) RuntimeWarning: Enable tracemalloc to get the object allocation traceback Message Sent!
两台设备均安装了Python 3.9.0,且我确认都使用telegram 0.0.1版本,代码里也没有用到async,这个错误让我很困惑。我的代码如下:
import telegram my_token = 'blahblahblah' def send(msg, chat_id, token=my_token): """ Send a message to a telegram user or group specified on chatId chat_id must be a number! """ bot = telegram.Bot(token=token) bot.sendMessage(chat_id=chat_id, text=msg) print('Message Sent!') MessageString = 'Testing from virtual server' print(MessageString) send(MessageString, '-blahblah', my_token )
这段代码逻辑非常简单,在我笔记本上每次运行都100%正常,我不清楚两台设备的差异在哪里,请问有什么解决思路?
内容的提问来源于stack exchange,提问作者Andy B
相关产品推荐
相关产品推荐

