将flask项目部署到阿里云上运行flask run时报错AttributeError: 'NoneType' object has no attribute 'SSLContext'


#1

Traceback (most recent call last):
File “/root/.virtualenvs/flask_blog/bin/flask”, line 8, in
sys.exit(main())
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/flask/cli.py”, line 966, in main
cli.main(prog_name=“python -m flask” if as_module else None)
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/flask/cli.py”, line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/click/core.py”, line 1135, in invoke
sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/click/core.py”, line 641, in make_context
self.parse_args(ctx, args)
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/click/core.py”, line 940, in parse_args
value, args = param.handle_parse_result(ctx, opts, args)
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/click/core.py”, line 1476, in handle_parse_result
value = invoke_param_callback(
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/click/core.py”, line 96, in invoke_param_callback
return callback(ctx, param, value)
File “/root/.virtualenvs/flask_blog/lib/python3.8/site-packages/flask/cli.py”, line 742, in _validate_key
is_context = isinstance(cert, ssl.SSLContext)
AttributeError: ‘NoneType’ object has no attribute ‘SSLContext’


#2

Python 版本大于 2.7.8 按理说不会出现这个问题,有可能是依赖管理工具或是 Python 版本的问题。麻烦提供下面的信息:

  • OS 和版本
  • Python 发行版来源
  • Flask 版本
  • 安装 Flask 时使用的工具和版本

可以试试重装 Python、pip 和 Flask(以及其他使用的依赖管理工具)……


#4

是的,Python安装的时候没有带ssl模块

试试用系统的包管理工具安装openssl-devel包(不同系统名称有差异),然后重新安装 Python

还有如果没有足够的知识不建议从源码编译Python,尽量通过系统提供的包管理器安装