Bank
Bank

Reputation: 75

Invalid token error in Telegram Bot API

I'm new to telegram bot api. I installed telegrom package 📦 and started to run my first code. but I cannot run my first code ! Can anyone know why this is happening? what should I do ? Thank you 🙏

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import telegram
>>> bot = telegram.Bot(token='TOKEN')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/telegram/bot.py", line 53, in __init__
    self.token = self._validate_token(token)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/telegram/bot.py", line 79, in _validate_token
    raise InvalidToken()
telegram.error.InvalidToken: Invalid token
>>>

Upvotes: -1

Views: 9671

Answers (1)

Shinlos
Shinlos

Reputation: 135

For your line bot = telegram.Bot(token='TOKEN')

You need to replace 'TOKEN' with your bot's token, as the string 'TOKEN' is just a placeholder. You may generate a bot token by talking to BotFather and creating a new bot.

Upvotes: 2

Related Questions