Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python telebot got unexpected response

I have been using my Telegram bot for sending me different notifications from my desktop computer using python's telebot library. Everything was working properly for quite a long time, but one day it stopped working.

Here's the code (Python 2.7):

import telebot
import socket

TELEBOT_TOKEN = '<token>'
CHAT_ID = <chat id>

bot = telebot.TeleBot(TELEBOT_TOKEN)

def notify(message):
    bot.send_message(CHAT_ID, 'Notification from ' + socket.gethostname() + ':\n' + message)

notify('Hello world!')

When I try doing this in the interpreter, I get this:

Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import telebot
>>> TELEBOT_TOKEN = '<token>'
>>> CHAT_ID = <chat id>
>>> bot = telebot.TeleBot(TELEBOT_TOKEN)
>>> bot.send_message(CHAT_ID, 'Hello world!')
{'ok': False, 'error': 'Got unexpected response. (404) - {"ok":false,"error_code":404,"description":"Not Found"}'}

Seems that I will get this error on any request

>>> bot.get_me()
{'ok': False, 'error': 'Got unexpected response. (404) - {"ok":false,"error_code":404,"description":"Not Found"}'}

I also tried using direct HTTPS Telegram bot API in the browser - typed this

https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat id>&text=Test

in the address line and it did the thing!

It also works with Python's requests library

>>> import requests
>>> res = requests.get('https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat id>&text=Test')

And finally, it works with the very same code on my two servers (VDS) without any troubles.

I recently installed scapy, if it has anything to do with this (maybe it caused the problem?)

EDIT: uninstalling scapy didn't help.

I tried rebooting the computer, and the router, but nothing changed.

What can be wrong with my computer?

like image 262
Andrew Che Avatar asked Mar 12 '17 19:03

Andrew Che


1 Answers

bot = telebot.TeleBot(TOKEN)
bot.config['api_key'] = TOKEN
like image 86
Nurlan Joldibaev Avatar answered Oct 08 '22 14:10

Nurlan Joldibaev