0
Google App Engineを設定して、pubsubから通知を読み込もうとしています。 //.appspot.com:PythonでGoogle Appengineにアプリを正常にデプロイした後のウェブURLにエラーがあります
An internal server error occured:
name 'request' is not defined
Main.pyはコードの下に含まれています
import logging
from flask import Flask
import os
import requests
app = Flask(__name__)
@app.route('/pubsub/push', methods=['POST'])
def pubsub_push():
if (request.args.get('token', '') !=
current_app.config['PUBSUB_VERIFICATION_TOKEN']):
return 'Invalid request', 400
envelope = json.loads(request.data.decode('utf-8'))
payload = base64.b64decode(envelope['message']['data'])
MESSAGES.append(payload)
# Returning any 2xx status indicates successful receipt of the message.
return 'OK', 200
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'GET':
return render_template('index.html', messages=MESSAGES)
data = request.form.get('payload', 'Example payload').encode('utf-8')
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(
current_app.config['PROJECT'],
current_app.config['PUBSUB_TOPIC'])
publisher.publish(topic_path, data=data)
return 'OK', 200
@app.errorhandler(500)
def server_error(e):
logging.exception('An error occurred during a request.')
return """
An internal error occurred: <pre>{}</pre>
See logs for full stacktrace.
""".format(e), 500
if __name__ == '__main__' :
app.run(host='127.0.0.1',port=8080,debug=True)
この問題に関するすべてのヘルプははるかに高く評価され成功し、アプリの展開の後、それはHTTPSに私にエラーを与えています。 Accessing Request Dataから
どうもありがとうダン。その問題は解決されました。さて、私は "name 'MESSAGES'が定義されていません。メッセージをインポートする必要がありますか?またはコード内に構文エラーがありますか?ありがとうございます。 – Shikha
はい。文法エラー、それらは 'SyntaxError'を発生させます。 –
私はMESSAGES = []を定義しましたが、そのエラーはなくなりましたが、現在、このエラーの"内部サーバーエラー "index.htmlの助けを借りていますか?いくつかの場所 – Shikha