简体   繁体   中英

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:

[ status_code 不正确1

Here is the code that returns the response (note: I tried both 500 and '500', and both have the same effect):

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? 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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