python 远程机器人收到意外响应
python telebot got unexpected response
我一直在使用我的 Telegram 机器人通过 python 的远程机器人库从我的台式计算机向我发送不同的通知。很长一段时间一切正常,但有一天它停止工作。
这是代码 (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!')
当我尝试在解释器中执行此操作时,我得到以下信息:
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"}'}
似乎我会在任何请求时收到此错误
>>> bot.get_me()
{'ok': False, 'error': 'Got unexpected response. (404) - {"ok":false,"error_code":404,"description":"Not Found"}'}
我还尝试在浏览器中使用直接 HTTPS Telegram bot API - 输入这个
https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat id>&text=Test
在地址行中,它做到了!
它也适用于 Python 的请求库
>>> import requests
>>> res = requests.get('https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat id>&text=Test')
最后,它与我的两台服务器 (VDS) 上的非常相同代码一起工作,没有任何问题。
我最近安装了scapy,是否与此有关(可能是问题所在?)
编辑: 卸载 scapy 没有帮助。
我尝试重新启动计算机和路由器,但没有任何改变。
我的电脑可能出了什么问题?
bot = telebot.TeleBot(TOKEN)
bot.config['api_key'] = TOKEN
我一直在使用我的 Telegram 机器人通过 python 的远程机器人库从我的台式计算机向我发送不同的通知。很长一段时间一切正常,但有一天它停止工作。
这是代码 (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!')
当我尝试在解释器中执行此操作时,我得到以下信息:
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"}'}
似乎我会在任何请求时收到此错误
>>> bot.get_me()
{'ok': False, 'error': 'Got unexpected response. (404) - {"ok":false,"error_code":404,"description":"Not Found"}'}
我还尝试在浏览器中使用直接 HTTPS Telegram bot API - 输入这个
https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat id>&text=Test
在地址行中,它做到了!
它也适用于 Python 的请求库
>>> import requests
>>> res = requests.get('https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat id>&text=Test')
最后,它与我的两台服务器 (VDS) 上的非常相同代码一起工作,没有任何问题。
我最近安装了scapy,是否与此有关(可能是问题所在?)
编辑: 卸载 scapy 没有帮助。
我尝试重新启动计算机和路由器,但没有任何改变。
我的电脑可能出了什么问题?
bot = telebot.TeleBot(TOKEN)
bot.config['api_key'] = TOKEN