本文介绍了AttributeError:'NoneType'对象在Win10上的PyCharm 2018.3.7中没有运行烧瓶脚本的属性'SSLContext'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用flask运行Hello world脚本:

Running the Hello world script using flask:

# coding=utf-8
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"

我收到以下错误:

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

PyCharm中的配置应该正确:

Configuration in PyCharm should be correct:

烧瓶1.1.1已安装在anaconda3中环境。
Im在Win10 Home上使用PyCharm 2018.3.7。

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!

推荐答案

FLASK_APP 应该具有烧瓶模块。

FLASK_APP should have your flask module.

会有所帮助。

顺便说一句,pycharm提供了创建flask应用程序的简便方法。 也会为您提供帮助。

BTW, pycharm provides easy way to create flask app. This link also helps you.

这是我的简单示例。

$ 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 -

这篇关于AttributeError:'NoneType'对象在Win10上的PyCharm 2018.3.7中没有运行烧瓶脚本的属性'SSLContext'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 23:23