簡體   English   中英

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

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

即使 AWS Lambda 服務器發回 500,我也收到 200 的 status_code:

[status_code 不正確1

這是返回響應的代碼(注意:我嘗試了 500 和 '500',兩者效果相同):

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

這是在燒瓶中啟動響應的代碼:

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

statusCode 正確為 500,因為輸入不正確,但這不應該反映在 status_code 屬性中嗎? 知道為什么會發生這種情況嗎? 非常感謝大家。

您收到 status_code 200(成功 HTTP 請求的標准響應。)因為服務器正常,服務器已到達並且處理也已執行。

唯一的問題是與您正在測試的用戶不匹配,因此這不會導致 status_code 500(內部服務器錯誤)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM