下午去幫大哥部署畢設.
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.
原文在這,更多可以看參考里的鏈接.
希望對同樣遇到這個問題的朋友有幫助.