【Azure 应用服务】Azure Function HTTP Trigger 遇见奇妙的500 Internal Server Error: Failed to forward request...

问题描述

使用 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号代码。


image.png

第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啊!


image.png

但是为了验证是这里的问题。修改代码,设置 status_code 为200后,再次部署到Azure Function中。 经过测试,奇妙的500错误消息。


image.png

如此可以成功判断: 是由于status_code为1导致了Failed to forward request to http://169.254.130.x的异常。

至此,问题解决。关于为什么status_code不能设置为1,并且去请求http://169.254.130.x 得地址,因为无法在云环境中Debug而无从得出结论。

【如以后有更多的资料后,在进行分析。。。】

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

分类: 【Azure 应用服务】

标签: App Service, Azure Function, Failed to forward request to http://169.254.130.7., 500 Internal Server Error

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容