• 카테고리

    질문 & 답변
  • 세부 분야

    블록체인

  • 해결 여부

    미해결

텔레그램 api 연동

18.10.27 20:38 작성 조회수 402

0

--inflearn_telegram.py ------------

import telegram

my_token = '796750774:AAFjR6ckBvyejTA9lB20TBXloi9qOydNIAA'

bot = telegram.Bot(token = my_token)

chat_id = '684872243'

message = '반갑습니다.'

bot.sendMessage(chat_id=chat_id, text=message)

  • 셋팅하고 실행하였으나 아래와 같은 메세지만 계속 나옵니다

    혹 아나콘다 잘못 되어나 해서 파이참까지 재 설치함

    시스템은 삼성노트북 i5 16G windows10 pro

    python 3.6.4 (Anaconda 3.5.1.0 32bit)' 파이참 32bit

    --python -m pip install 및 upgrade

    • pip, requests, python-telegram-bot
    • ta-lib, numpy, pandas

--파이참 error 내용-----------------------

C:asdataAnaconda3python.exe C:/asdata/madegopax/inflearn_telegram.py

Traceback (most recent call last):

File "C:/asdata/madegopax/inflearn_telegram.py", line 4, in

bot = telegram.Bot(token = my_token)

AttributeError: module 'telegram' has no attribute 'Bot'

Process finished with exit code 1

--웹부라우저에서 실행------

https://api.telegram.org/bot796750774:AAFjR6ckBvyejTA9lB20TBXloi9qOydNIAA/getupdates

{ "ok": true, "result": [{ "update_id": 843898929,

"message": { "message_id": 5, "from": { "id": 684872243, "is_bot": false, "first_name": " uc815 uc6a9", "last_name": " uae40", "language_code ":"ko-KR "},"chat ": {"id ": 684872243,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","type ":"private "}} 날짜 ": 1540610570,"text ":"hellow "}}, {"update_id ": 843898930,

"message": "{"message_id ": 6"from ": {"id ": 684872243,"is_bot ": false,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","language_code ":"ko-KR "},"chat ": {"id ": 684872243,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","type ":"private "}} 날짜 ": 1540610592,"text ":"frend "}}, {"update_id ": 843898931,

"message": "{"message_id ": 7"from ": {"id ": 684872243,"is_bot ": false,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","language_code ":"ko-KR "},"chat ": {"id ": 684872243,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","type ":"private "}} 날짜 ": 1540625698,"text ":"hellow "}}}}}--inflearn_telegram.py ------------

import telegram

my_token = '796750774:AAFjR6ckBvyejTA9lB20TBXloi9qOydNIAA'

bot = telegram.Bot(token = my_token)

chat_id = '684872243'

message = '반갑습니다.'

bot.sendMessage(chat_id=chat_id, text=message)

  • 셋팅하고 실행하였으나 아래와 같은 메세지만 계속 나옵니다

    혹 아나콘다 잘못 되어나 해서 파이참까지 재 설치함

    시스템은 삼성노트북 i5 16G windows10 pro

    python 3.6.4 (Anaconda 3.5.1.0 32bit)' 파이참 32bit

    --python -m pip install 및 upgrade

    • pip, requests, python-telegram-bot
    • ta-lib, numpy, pandas

--파이참 error 내용-----------------------

C:asdataAnaconda3python.exe C:/asdata/madegopax/inflearn_telegram.py

Traceback (most recent call last):

File "C:/asdata/madegopax/inflearn_telegram.py", line 4, in

bot = telegram.Bot(token = my_token)

AttributeError: module 'telegram' has no attribute 'Bot'

Process finished with exit code 1

--웹부라우저에서 실행------

https://api.telegram.org/bot796750774:AAFjR6ckBvyejTA9lB20TBXloi9qOydNIAA/getupdates

{ "ok": true, "result": [{ "update_id": 843898929,

"message": { "message_id": 5, "from": { "id": 684872243, "is_bot": false, "first_name": " uc815 uc6a9", "last_name": " uae40", "language_code ":"ko-KR "},"chat ": {"id ": 684872243,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","type ":"private "}} 날짜 ": 1540610570,"text ":"hellow "}}, {"update_id ": 843898930,

"message": "{"message_id ": 6"from ": {"id ": 684872243,"is_bot ": false,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","language_code ":"ko-KR "},"chat ": {"id ": 684872243,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","type ":"private "}} 날짜 ": 1540610592,"text ":"frend "}}, {"update_id ": 843898931,

"message": "{"message_id ": 7"from ": {"id ": 684872243,"is_bot ": false,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","language_code ":"ko-KR "},"chat ": {"id ": 684872243,"first_name ":" uc815 uc6a9 ","last_name ":" uae40 ","type ":"private "}} 날짜 ": 1540625698,"text ":"hellow "}}}}}

답변 1

답변을 작성해보세요.

0

telegram모듈이 없거나 참조를 잘못 하고있을 때 나오는 현상입니다.

현재 구동하고있는 환경 (venv or 전역) 에 제대로 telegram 패키지가 설치 돼 있는지 확인해주세요.

그래도 안되신다면

pip uninstall python-telegram-bot telegram

pip install python-telegram-bot

이 커맨드를 실행해 봐 주세요.

혹시 그래도 안되신다면 다시 질문 부탁드립니다.

감사합니다.