AWS Elastic Beanstalk上的Python Flask请求无问题
我有一段代码,它是一个post方法(Python Flask) 当我在本地运行应用程序并在postman上将json发布到时,我可以看到相同的json结果 但当我将我的应用程序推到aws elastic beanstalk上,并发布了相同的方法后,它返回了AWS Elastic Beanstalk上的Python Flask请求无问题,python,amazon-web-services,flask,amazon-elastic-beanstalk,Python,Amazon Web Services,Flask,Amazon Elastic Beanstalk,我有一段代码,它是一个post方法(Python Flask) 当我在本地运行应用程序并在postman上将json发布到时,我可以看到相同的json结果 但当我将我的应用程序推到aws elastic beanstalk上,并发布了相同的方法后,它返回了“``None```” 原因是什么 这就是json示例 { "api_app_id": "A02", "token": "Shh_its_a_seekrit&
“``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
仅在发送内容类型为application/json
的请求时有效。否则为None
如果没有内容类型,则应使用request.data
:
@application.route('/try', methods=['POST'])
def tryPost() :
content = "```" + str(request.data) + "```"
return content
谢谢@Marcin,但现在它像这样返回,我如何修复它;b'{\r\n\t“api\u app\u id”:“A02”、\r\n\t“token”:“Shh\u its\u a\u seekrit”、\r\n\t“container”:{\r\n\t\t“type”:“message”、\r\n\t\t“text”:“操作发起的原始消息的内容”\r\n\t}\r\n}@evvalKahraman我认为您只需返回
request.data
,没有str
操作。但是我无法与其他字符串连接:/@ŞevvalKahraman抱歉,我不知道您想要实现什么。为什么不在请求中传递application/json的内容类型呢?谢谢@Marcin,我想在slack上显示这些请求。我返回了str(request.data,“utf-8”),它可以正常工作。
@application.route('/try', methods=['POST'])
def tryPost() :
content = "```" + str(request.data) + "```"
return content