天天看點

【Azure 應用服務】Azure Function HTTP Trigger 遇見奇妙的500 Internal Server Error: Failed to forward

問題描述

使用 Azure Funciton App,在本地運作完全成功的Python代碼,釋出到Azure Function就出現了500  Internal Server Error. 而且錯誤消息也是莫名的 Failed to forward request to http://169.254.130.x。

2022-07-11T11:46:01.646550271Z Failed to forward request to http://169.254.130.7.

Encountered a System.Net.Http.HttpRequestException exception after 562.442ms with message: Received an invalid status line: 'HTTP/1.1 1 '..

Check application logs to verify the application is properly handling HTTP traffic.

問題解決

在Azure Function的Test/Run頁面,根據在代碼中添加的日志标簽,可以準确的定位到錯誤發生在29号代碼。

【Azure 應用服務】Azure Function HTTP Trigger 遇見奇妙的500 Internal Server Error: Failed to forward

 第29行代碼為:

return func.HttpResponse(f"Logic Hello, {dresult}. This HTTP triggered function executed successfully.",status_code=1)      

與預設生成的Python Function模闆代碼的差別隻有 status_code 設定為了1. 預設的沒有指定。

return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")      

是以非常懷疑就是這裡的問題. 檢視源碼,預設值就是200, 但是這裡也沒有說不允許設定為1啊!

【Azure 應用服務】Azure Function HTTP Trigger 遇見奇妙的500 Internal Server Error: Failed to forward

但是為了驗證是這裡的問題。修改代碼,設定 status_code 為200後,再次部署到Azure Function中。 經過測試,奇妙的500錯誤消息。

【Azure 應用服務】Azure Function HTTP Trigger 遇見奇妙的500 Internal Server Error: Failed to forward

如此可以成功判斷:

至此,問題解決。關于為什麼status_code不能設定為1,并且去請求http://169.254.130.x 得位址,因為無法在雲環境中Debug而無從得出結論。

【如以後有更多的資料後,在進行分析。。。】

上一篇: Git簡單指令2
下一篇: cephadm 監控