Python 2.7 Can';t为电报机器人设置webhook
我正在尝试在谷歌应用程序引擎中制作一个简单的电报机器人 当我在GAE中打开控制台并输入以下内容时,webhook设置得很好Python 2.7 Can';t为电报机器人设置webhook,python-2.7,google-app-engine,telegram-webhook,Python 2.7,Google App Engine,Telegram Webhook,我正在尝试在谷歌应用程序引擎中制作一个简单的电报机器人 当我在GAE中打开控制台并输入以下内容时,webhook设置得很好 curl -F "url=https://example.appspot.com:8443/<token>" -F "certificate=@certificate.pem" https://api.telegram.org/bot<token>/setWebhook 编辑: 我更改了app.yaml文件如下,但仍然无法设置web
curl -F "url=https://example.appspot.com:8443/<token>" -F "certificate=@certificate.pem"
https://api.telegram.org/bot<token>/setWebhook
编辑:
我更改了app.yaml文件如下,但仍然无法设置webhook。现在它给了我“502坏网关nginx”错误
您的
app.yaml
表示标准GAE环境,其中Flask应用程序仅通过app
变量及其处理程序/路由引用。如果uuuu name_uuuu='\uuuuu main\uuuu':
部分甚至可能不会执行。发件人:
可能感兴趣:是否收到任何错误消息?另外,请提供该服务的app.yaml文件,每当我运行该服务时,都会显示“Hello World”。当我尝试运行webhook()时,我得到“错误的请求浏览器(或代理)发送了一个此服务器无法理解的请求”。但我认为这是因为webhook-to-telegram根本没有设置(我在telegram-Bot API中使用getWebhookInfo进行了检查)。请注意,flex-env与标准版本有很大不同,您可能需要阅读一些内容。你做过港口转运吗?你是说我的python电报机器人需要一个灵活的环境?我对电报不熟悉。这取决于它能否在受限的标准环境沙箱中工作:。如果这不可能或太难,那么是的,您需要flex。另请参阅
import sys
import os
import time
from flask import Flask, request
import telegram
# CONFIG
TOKEN = '<token>'
HOST = 'example.appspot.com' # Same FQDN used when generating SSL Cert
PORT = 8443
CERT = "certificate.pem"
CERT_KEY = "key.pem"
bot = telegram.Bot(TOKEN)
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
@app.route('/' + TOKEN, methods=['POST','GET'])
def webhook():
update = telegram.Update.de_json( request.get_json(force = True), bot )
chat_id = update.message.chat.id
bot.sendMessage(chat_id = chat_id, text = 'Hello, there')
return 'OK'
def setwebhook():
bot.setWebhook(url = "https://%s:%s/%s" % (HOST, PORT, TOKEN), certificate = open(CERT, 'rb'))
if __name__ == '__main__':
context = (CERT, CERT_KEY)
setwebhook()
time.sleep(5)
app.run(host = '0.0.0.0', port = PORT, ssl_context = context, debug = True)
runtime: python27
api_version: 1
threadsafe: yes
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: ssl
version: latest
runtime: python
env: flex
entrypoint: gunicorn -b :8443 main:app
threadsafe: true
runtime_config:
python_version: 2
app = Flask(__name__)
...
if __name__ == '__main__':
# This is used when running locally. Gunicorn is used to run the
# application on Google App Engine. See entrypoint in app.yaml.
app.run(host='127.0.0.1', port=8080, debug=True)