파이썬에서 텔레그램으로 문자를 보내려고 하는데 코드에서 오류가 발생합니다.
오류가 발생하는 예제는 아래와 같ㅎ습니다.
import telegram
token = "OOOOOOOOOOOOOOOOOOOOOOOOOO"
chat_id = "OOOOOOOOO"
bot = telegram.Bot(token)
bot.send_message(chat_id, text='telegram chat test message...')
// 오류 메시지
RuntimeWarning: coroutine 'Bot.send_message' was never awaited
bot.send_message(chat_id, text='telegram chat test message...')
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
웹에서 검색한 await조치 방안 코드를 참고하여 작성하니 텔레그램으로 정상적으로 메시지가 출력이 됩니다.
import telegram
import asyncio
async def main():
token = "OOOOOOOOOOOOOOOOOOOOOOOOOO"
chat_id = "OOOOOOOOO"
bot = telegram.Bot(token)
await bot.send_message(chat_id, text='telegram chat test message...')
asyncio.run(main())
chat_id를 얻는 코드가 정상적으로 수행되지 않아서 telegram의 GetIDs bot을 이용하여 chat_id를 찾아 입력해 주었습니다.
다른 웹검색을 해보니,,,
python-telegram-bot 20 버전에서 발생하는 오류로 telegram을 downgrade 하면 해결되네요...
pip install --upgrade python-telegram-bot==13.14
'▶ 데이터분석 전문가' 카테고리의 다른 글
공공데이터포털의 API 인증키를 얻어봅시다. (2) | 2023.05.28 |
---|---|
데이터 분석을 위하여 R을 사용해볼까요? (0) | 2023.05.28 |
파이썬과 친해지기 (with Anaconda, JupyterLab) (0) | 2023.05.11 |
구글 바드 (Google Bard) - chatGPT와 비교 (0) | 2023.05.11 |
웹 크롤링 (0) | 2023.04.25 |
댓글