- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题是关于使用 pyTelegramBotAPI 模块在 Telegram 机器人中使用 webhook。
我正在使用 pythonanywhere.com 来托管机器人。
以下代码工作正常:
from flask import Flask, request
import telebot
secret = "A_SECRET_NUMBER"
bot = telebot.TeleBot ('YOUR_AUTHORIZATION_TOKEN')
bot.set_webhook("https://YOUR_PYTHONANYWHERE_USERNAME.pythonanywhere.c..
}".format(secret), max_connections=1)
app = Flask(__name__)
@app.route('/{}'.format(secret), methods=["POST"])
def telegram_webhook():
update = request.get_json()
if "message" in update:
text = update["message"]["text"]
chat_id = update["message"]["chat"]["id"]
bot.sendMessage(chat_id, "From the web: you said '{}'".format(text))
return "OK"
# Process webhook calls
@app.route(WEBHOOK_URL_PATH, methods=['POST'])
def webhook():
if flask.request.headers.get('content-type') == 'application/json':
json_string = flask.request.get_data().decode('utf-8')
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return ''
else:
flask.abort(403)
# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.reply_to(message,
("Hi there, I am EchoBot.\n"
"I am here to echo your kind words back to you."))
# Handle all other messages
@bot.message_handler(func=lambda message: True, content_types=['text'])
def echo_message(message):
bot.reply_to(message, message.text)
最佳答案
您应该在 TeleBot 构造函数中禁用线程,如下所示:
bot = telebot.TeleBot('YOUR_AUTHORIZATION_TOKEN', threaded=False)
关于flask - 通过 pythonanywhere.com 上的 pyTelegramBotAPI 和 Flask 使用 Telegram bot webhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42251231/
我正在关注 Djangogirls 教程,根据该教程,我在 Django 管理员的博客中添加了新帖子。我使用 Django 模板创建了一个模板来显示此动态数据。我通过在浏览器中打开 127.0.0.1
安装模块时遵循。尝试安装其他模块时收到类似消息。 非常感谢您的帮助。谢谢! [Errno 13]权限被拒绝:'/usr/local/lib/python2.7/dist-p 您指定的安装目录(通过 -
问题是什么? 我在 Pythonanywhere.com 上运行 This error can be due to the fact that ImageMagick is not installed
我有一个初学者 PythonAnywhere 帐户,帐户比较页面指出,该帐户具有“访问外部 Internet 站点:仅通过 HTTP(S) 访问特定站点”的功能。 所以我知道只有某些主机可以通过 HT
我正在尝试在 PythonAnywhere 上上传我的网络应用程序,但我无法做到这一点。我尝试了很多方法并在谷歌上进行了搜索,但我无法解决它。请告诉我我缺少什么或我应该在此处添加哪些信息。我还添加了来
我有一个 python 脚本,当我转到文件并点击运行时,它可以正常运行。但是,当调度程序运行脚本时,该脚本会失败。可能是什么原因造成的? 这是我的脚本: import time import os i
我正在使用 Flask Mega Tutorial 在 pythonanywhere 中构建应用程序当我在我的电脑上运行时它工作正常。当我将其上传到 PA 时出现 404 错误。 我的结构 /micr
当我在 PythonAnywhere 查看计划任务的日志时,我发现它们充满了如下语句: 2012-06-07 11:09:16 -- 完成任务,耗时 11.00 秒,返回代码为 0。 2012-06-
我是 Pythonanywhere 的新手,想安装“soundcloud”Python 模块。我打开了 Bash 控制台并输入了 pip install --user soundcloud 命令。 它
我正在尝试在 PythonAnywhere 上部署我的应用程序。一切正常,但是当我调用一个函数时,我的应用程序失败了。 异常类型:JSONDecodeError 异常值:期望值:第 1 行第 1 列(
我想将 django Web 应用程序托管到 pythonanywhere。我在 godaddy 有一个域名。我按照此 link 中的说明进行操作。在godaddy的DNS管理页面下,我设置CNAME
我在 Flask 应用程序中使用 rauth 库。错误日志显示错误 ImportError: No module named rauth. 如何处理这个问题。 最佳答案 根据documentation
我按照教程创建了一个简单的数据库支持的 Flask 网站。 Here 我成功地遵循了本教程,但我正在努力使用这种方法创建多个表。我希望该表被称为“成分”。这是我的 Flask_app.py 代码 fr
我是 pythonanywhere 的新手,目前正在使用它和 bottle 框架部署我的第一个应用程序。我已经使用在线控制台创建了一个数据库,但我不知道访问它的语法。它与在本地部署时的语法相同吗?或者
所以我想在 pythonanywhere 上部署我的网站。我创建了 virtualenv,安装了 Django 和我的网站所需的所有应用程序。我创建了新应用程序并将其与我从 GitHub 克隆的项目连
此代码是在 pythonanywhere (linux) 上托管的 python 3.5。 我正在使用 with open 来管理一个非阻塞的 flock,但有时调度的进程会遇到异常,导致作业终止;没
我是 pythonanywhere 的新手。我想知道如何从本地 csv 文件(其中有很多,超过 1,000 个)将数据加载到 mysql 表中。假设 csv 文件的文件夹路径是 d:/data。怎么写
我对 Pythonanywhere 完全陌生,我不知道为什么静态文件没有加载...这是我存储 css 和图像的路径,即 static/images/wikiLang.png 等 /static/adm
我想提交一个有文件字段的表单,在开发模式下我可以成功提交,但是当涉及到 pythonanywhere 时,我被重定向到我的自定义失败页面,这意味着表单没有通过。 表单在没有附件时被保存,它在 deve
使用 Python 2.7 和 Django 1.10.4,我尝试将我的应用程序部署到 pythonanywhere,但我不断收到此错误。 错误日志 wsgi.py import os import
我是一名优秀的程序员,十分优秀!