2

I am trying to create Telegram Bot on my raspberry pi 3

import telepot
bot=telepot.Bot('*tokenhere*')
bot.getMe()

After this i am getting telepot.exception.UnauthorizedError with error code 401. Is it saying token is not correct?

3
  • Just for clarity.. you did replace 'tokenhere' with a valid token? – Piotr Kula Jun 16 '16 at 6:50
  • @ppumkin yes I have replaced it with token which i have got after creating a bot using BotFather – BhanuReddy Jun 16 '16 at 9:25
  • For those who are facing the same issue please use below link api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/… and replace token with your token. This worked for me. source: Telegram Bot API – BhanuReddy Jun 22 '16 at 15:53
1

Did you follow all of the steps in How do I Create a Bot?

From the website:

  1. How do I create a bot?
    There's a… bot for that. Just talk to BotFather (described below in 6.) and follow a few simple steps. Once you've created a bot and received your authorization token, head down to the Bot API manual to see what you can teach your bot to do.
    You may also like to check out some code examples here »

The website goes on to describe BotFather

  1. BotFather

BotFather is the one bot to rule them all. It will help you create new bots and change settings for existing ones.

Create a new bot
Use the /newbot command to create a new bot. The BotFather will ask you for a name and username, then generate an authorization token for your new bot.

The name of your bot will be displayed in contact details and elsewhere.

The Username is a short name, to be used in mentions and telegram.me links. Usernames are 5-32 characters long and are case insensitive, but may only include Latin characters, numbers, and underscores. Your bot's username must end in ‘bot’, e.g. ‘tetris_bot’ or ‘TetrisBot’.

The token is a string along the lines of 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw that will be required to authorize the bot and send requests to the Bot API.

Generate an authorization token for your bot
If your existing token is compromised or you lost it for some reason, use the /token command to generate a new one.

Edit settings
The remaining commands are pretty self-explanatory:

It then goes on to explain the remaining commands.

9
  • Could you please list an outline of those steps here. – Darth Vader Jun 16 '16 at 7:12
  • @John Burger I have received a token and used it to test account bot=telepot.Bot('tokenhere') bot.getMe() #after this line i am getting unauthorized Error as I have mentioned in my question. Do I need to generate another token and check? – BhanuReddy Jun 16 '16 at 9:20
  • @DarthVader you can find those steps here instructables.com/id/Set-up-Telegram-Bot-on-Raspberry-Pi – BhanuReddy Jun 16 '16 at 9:24
  • Does the token 'look' like the one in the example? Not exactly, of course, but with the same number of characters etc? And you are using https to connect, yes? – John Burger Jun 16 '16 at 9:25
  • @JohnBurger yes token look like one in the example and same number of characters. I am not sure about using https connection, How can I make sure that it is using https. – BhanuReddy Jun 16 '16 at 9:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.