问题
Running the Hello world script using flask:
# coding=utf-8
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
I get the following error(s):
C:\anaconda3\python.exe C:/anaconda3/Scripts/flask-script.py run
Traceback (most recent call last):
File "C:/anaconda3/Scripts/flask-script.py", line 9, in <module>
sys.exit(main())
File "C:\anaconda3\lib\site-packages\flask\cli.py", line 966, in main
cli.main(prog_name="python -m flask" if as_module else None)
File "C:\anaconda3\lib\site-packages\flask\cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "C:\anaconda3\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "C:\anaconda3\lib\site-packages\click\core.py", line 1135, in invoke
sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
File "C:\anaconda3\lib\site-packages\click\core.py", line 641, in make_context
self.parse_args(ctx, args)
File "C:\anaconda3\lib\site-packages\click\core.py", line 940, in parse_args
value, args = param.handle_parse_result(ctx, opts, args)
File "C:\anaconda3\lib\site-packages\click\core.py", line 1477, in handle_parse_result
self.callback, ctx, self, value)
File "C:\anaconda3\lib\site-packages\click\core.py", line 96, in invoke_param_callback
return callback(ctx, param, value)
File "C:\anaconda3\lib\site-packages\flask\cli.py", line 742, in _validate_key
is_context = isinstance(cert, ssl.SSLContext)
AttributeError: 'NoneType' object has no attribute 'SSLContext'
Process finished with exit code 1
Configuration in PyCharm should be correct:
Flask 1.1.1 already installed in anaconda3 environment. Im using PyCharm 2018.3.7 on Win10 Home.
Could you please help me how to fix this or what does the error says? Thank you in advance!
回答1:
FLASK_APP
should have your flask module.
flask quickstart would be helpful.
you need to tell your terminal the application to work with by exporting the FLASK_APP environment variable
BTW, pycharm provides easy way to create flask app. This link also helps you.
Here is my simple example.
$ cat hello.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "hello world"
$ env FLASK_APP=hello.py flask run
* Serving Flask app "hello.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [12/Apr/2020 12:13:04] "GET / HTTP/1.1" 200 -
来源:https://stackoverflow.com/questions/61162227/attributeerror-nonetype-object-has-no-attribute-sslcontext-running-flask-sc