python - AWS Elastic Beanstalk 上的 Python Flask 请求无问题
问题描述
我有这段代码,它是一个 post 方法(Python Flask),
@application.route('/try', methods=['POST'])
def tryPost() :
content = "```" + str(request.json) + "```"
return jsonify(content)
当我在本地运行应用程序并将邮递员上的 json 发布到http://127.0.0.1:5000/try时,我可以看到相同的 json 结果。
但是在我将我的应用程序推送到 aws elastic beanstalk 之后,我发布了它返回的相同方法"```None```"
原因是什么?
这是示例 json
{
"api_app_id": "A02",
"token": "Shh_its_a_seekrit",
"container": {
"type": "message",
"text": "The contents of the original message where the action originated"
}
}
解决方案
request.json
Content-Type
仅当您使用of发送请求时才有效application/json
。否则为None
。
如果没有内容类型,您应该使用request.data
:
@application.route('/try', methods=['POST'])
def tryPost() :
content = "```" + str(request.data) + "```"
return content