Flask 遇到 500 Internal Server Error 解决方法

下午去帮大哥部署毕设.
Postman请求接口一直显示500 Internal Server Error,Proxy Connection Refused.
调整了代理设置,VPS的安全策略,问题依旧没有解决.
最后发现是一行代码出现了问题.

app.run(debug=True,port=5000)

原本是这么写的,乍一看没什么问题.
但是它默认只能接收局域网内的访问.
看官方文档,想要外部访问的话,还需要加上host=0.0.0.0,开启对所有ip的监听模式

app.run(debug=True,host='0.0.0.0',port=5000)

Externally Visible Server
If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.
If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding --host=0.0.0.0 to the command line:
$ flask run --host=0.0.0.0
This tells your operating system to listen on all public IPs.

原文在这,更多可以看参考里的链接.
希望对同样遇到这个问题的朋友有帮助.

参考

  1. https://flask.palletsprojects.com/en/1.1.x/quickstart/#a-minimal-application
posted @ 2021-04-08 16:29  rpish  阅读(3903)  评论(0编辑  收藏  举报