发布webhook:python中的502 Bad Gateway错误

时间:2018-02-07 07:02:36

标签: python post

导入urllib     导入json     进口口     来自flask进口烧瓶     来自烧瓶进口申请     来自flask import make_response

app = Flask(__name__)
print("after Flask")
@app.route("/webhook", methods=['POST'])
def webhook():
    print("inside webhook definition")
    req=request.get_json(silent=True, force=True)
    print("Request:")
    print(json.dumps(req,indent=4))
    res=makeWebhookResult(req)
    res=json.dumps(res,indent=4)
    print(res)
    r= make_response(res)
    r.header['Content-type']='application/json'
    return r

    def makeWebhookResult(req):
        print("before if")
        if req.get("result").get("action")!="pizzatop":
            print("inside if")
            return()
        result=req.get("result")
        print("outside if")
        parameters=result.get("parameteres")
        top=parameteres.get("Toppings")
        cast= {'Cheese':'Available','Onion':'Available','mushroom':'Not Available'}
        speech="the "+top+"pizza is:"+str(cast[top])
        print("Response")
        print(speech)
        return {
            "speech": speech,
            "displayText": speech,
            "source": "MyPizzaBot"
        }
        if __name__ == '__main__':
            port=int(os.getenv('PORT',80))
            print("Starting app on port %d"%(port))
            app.run(debug=True,port=port,host='192.168.100.1')

这是我的代码。当我运行python显示没有错误但ngrok显示未找到POst / webhook 404。 我尝试了很多解决方案,但没有运气。任何人都可以帮助我解决我错过的问题吗?

0 个答案:

没有答案