【问题标题】:python telebot got unexpected responsepython telebot得到了意外的响应
【发布时间】:2017-08-02 19:20:02
【问题描述】:

我一直在使用我的 Telegram 机器人使用 python 的 Telebot 库从我的台式计算机向我发送不同的通知。在很长一段时间内一切都正常工作,但有一天它停止了工作。

这是代码(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 的 requests 库

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

最后,它可以在我的两台服务器 (VDS) 上使用非常相同的代码,没有任何问题。

我最近安装了 scapy,如果它与此有关(也许它导致了问题?)

编辑:卸载 scapy 没有帮助。

我尝试重新启动计算机和路由器,但没有任何改变。

我的电脑出了什么问题?

【问题讨论】:

    标签: python python-2.7 telegram-bot


    【解决方案1】:
    bot = telebot.TeleBot(TOKEN)
    bot.config['api_key'] = TOKEN
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 2020-10-13
      • 1970-01-01
      相关资源
      最近更新 更多