简体   繁体   English

Python requests.post() 方法命令返回 200 status_code 属性而不是 500

[英]Python requests.post() method command returns 200 status_code attribute instead of 500

I'm getting a status_code of 200 even though the AWS Lambda server is sending back 500:即使 AWS Lambda 服务器发回 500,我也收到 200 的 status_code:

[ [status_code 不正确1

Here is the code that returns the response (note: I tried both 500 and '500', and both have the same effect):这是返回响应的代码(注意:我尝试了 500 和 '500',两者效果相同):

return {
    'statusCode': '500',
    'headers': {
       'Content-Type': 'application/json',
    },
    'body': 'Authentication failed!'
}

And here is the code that initiates the response in flask:这是在烧瓶中启动响应的代码:

response = requests.post(URLS.sign_in.get("endpoint"), 
           json={"user": form.email.data, "pass": form.password.data})

The statusCode is correctly 500, as the input is incorrect, but shouldn't this be reflected in the status_code property? statusCode 正确为 500,因为输入不正确,但这不应该反映在 status_code 属性中吗? Any idea why this could be happening?知道为什么会发生这种情况吗? Thank you all so much.非常感谢大家。

You are getting status_code 200(Standard response for successful HTTP requests.) because the server is ok, the sever was reached and the processing was also performed.您收到 status_code 200(成功 HTTP 请求的标准响应。)因为服务器正常,服务器已到达并且处理也已执行。

The only problem is that there is no match for the user whom you are testing with, so this will not result in status_code 500 (Internal Server Error).唯一的问题是与您正在测试的用户不匹配,因此这不会导致 status_code 500(内部服务器错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM