Flask 遇到 500 Internal Server Error 解决方法

摘要:
下午,我去帮大哥布置设计。Postman请求接口始终显示500InternalServerError,ProxyConnectionRejected。代理设置已调整,VPS安全策略尚未解决。最后,我发现一行代码有问题。应用程序。run(debug=True,port=5000)最初是这样编写的。乍一看,没有问题。但默认情况下,它只能在局域网内接收访问。请参阅官方文档。如果要从外部访问,还需要添加主机

下午去帮大哥部署毕设.
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

免责声明:文章转载自《Flask 遇到 500 Internal Server Error 解决方法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇js压缩 uglify(2)pytest框架+allure2框架的基本使用(2019-09-03更新)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

[Python自学] Flask框架 (3) (路由、CBV、自定义正则动态路由、请求处理流程、蓝图)

一、路由系统 1.浅析@app.route的源码 我们使用@app.route("/index")可以给视图函数加上路由映射。我们分析一下@app.route装饰器的实现源码: def route(self, rule, **options): def decorator(f): endpoint = options.pop("en...

flask 使用Flask-SQLAlchemy管理数据库(连接数据库服务器、定义数据库模型、创建库和表) --

使用Flask-SQLAlchemy管理数据库 扩展Flask-SQLAlchemy集成了SQLAlchemy,它简化了连接数据库服务器、管理数据库操作会话等各种工作,让Flask中的数据处理体验变得更轻松。首先使用pipenv安装Flask-SQLAlchemy以及其依赖(主要是SQLAlchemy): pipenv install flask-sqla...

Flask 基础组件(二):配置文件

配置参数 flask中的配置文件是一个flask.config.Config对象(继承字典),默认配置为: { 'DEBUG': get_debug_flag(default=False), 是否开启Debug模式 'TESTING':...

基于Python的Web应用开发实战——3 Web表单

第2章中介绍的 请求对象 包含客户端发出的所有请求信息。 其中, request.form 能获取 POST请求 中提交的表单数据。 尽管Flask的请求对象提供的信息足够用于处理Web表单,但有些任务很单调,而且要重复操作。 比如,生成表单的HTML代码和验证提交的表单数据。 Flask-WTF(https://flask-wtf.readthedocs...

Flask之Sqlalchemy

Sqlalchemy 开发文档:https://www.jianshu.com/p/0ad18fdd7eed 创建数据库 安装 pip instal flask-sqlalchemy 两种配置方法 # 两种配置数据库方法 第一种app.config from flask import Flask import pymysql from flask_sq...

基于Flask的 api(三)

使用flask的RESTful扩展库 flask-restful 安装 pip install flask-restful eg: 最简单的api fromflask import Flask fromflask_restful import Api, Resource app =Flask(__name__) api =Api(app) classH...