【发布时间】:2020-06-02 19:20:22
【问题描述】:
import requests
from flask import Flask, redirect, url_for
import pandas as pd
from bokeh.plotting import figure, output_file, show
from bokeh.resources import CDN
from bokeh.embed import file_html
def get_total_confirmed_us():
output_file("COVID_19_Data.html")
country = 'united-states'
status = 'confirmed'
url = 'https://api.covid19api.com/total/country/{}/status/{}?from=2020-05-01T00:00:00Z&to=2020-05-30T00:00:00Z'.format(country, status)
response = requests.get(url)
us_confirmed = response.json()
us_confirmed = pd.DataFrame(us_confirmed)
plot = figure()
plot.line(range(len(us_confirmed)), us_confirmed['Cases'])
show(plot)
app = Flask(__name__)
@app.route('/', methods = ['GET'])
def run():
return redirect(url_for('static', filename = 'COVID_19_Data.html'))
%tb
if __name__ == "__main__":
app.debug = True
app.run(host = "0.0.0.0", port = 5000, use_reloader = False)
每次我在本地运行我的 Flask 应用程序时,我都会得到一个系统退出。有谁知道如何解决这一问题?我将向您显示以下错误:
<ipython-input-1-9f0d70378116> in <module>
31 app.debug = True
32 get_ipython().run_line_magic('tb', '')
---> 33 app.run(host = "0.0.0.0", port = 5000)
~\Anaconda3\lib\site-packages\flask\app.py in run(self, host, port, debug, load_dotenv, **options)
988
989 try:
--> 990 run_simple(host, port, self, **options)
991 finally:
992 # reset the first request information if the development server
~\Anaconda3\lib\site-packages\werkzeug\serving.py in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context) 1005 from ._reloader import run_with_reloader 1006
-> 1007 run_with_reloader(inner, extra_files, reloader_interval, reloader_type) 1008 else: 1009 inner()
~\Anaconda3\lib\site-packages\werkzeug\_reloader.py in run_with_reloader(main_func, extra_files, interval, reloader_type)
330 reloader.run()
331 else:
--> 332 sys.exit(reloader.restart_with_reloader())
333 except KeyboardInterrupt:
334 pass
SystemExit: 1
* Serving Flask app "__main__" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: on * Restarting with stat An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
我是 Flask 的初学者,所以我不知道这个错误是什么意思。顺便说一句,我正在 Jupyter Notebook 上运行此代码并尝试创建一个 Flask 应用程序,我可以在其中显示我的 COVID 19 数据可视化,并在此错误解决后构建更多功能。
【问题讨论】:
-
该堆栈跟踪显示您发布的不同代码(32 是新的,33 是不同的)。你能先澄清一下吗?
标签: python flask web-applications data-visualization bokeh