在Windows Bash中使用pyOpenSSL库在Flask Web应用中尝试进行SSL认证时引发TypeError

时间:2019-06-25 06:09:09

标签: python python-2.7 flask werkzeug

我正在尝试设置Flask网络服务器以处理SSL认证。我正在使用Windows Bash,到目前为止,该工具一直工作良好。我在linux shell中做了'''pip install pyopenssl'''并在.py shell中添加了以下行:

if __name__ == '__main__':
    app.run(debug=True, ssl_context='adhoc')

当我尝试运行flask应用程序时,我得到了:

* Serving Flask app "wss" (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
 * Running on https://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 437-524-983
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/mnt/c/Users/***/Documents/my-ws/flask/local/lib/python2.7/site-packages/werkzeug/serving.py", line 962, in inner
    fd=fd,
  File "/mnt/c/Users/***/Documents/my-ws/flask/local/lib/python2.7/site-packages/werkzeug/serving.py", line 805, in make_server
    host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
  File "/mnt/c/Users/***/Documents/my-ws/flask/local/lib/python2.7/site-packages/werkzeug/serving.py", line 716, in __init__
    ssl_context = generate_adhoc_ssl_context()
  File "/mnt/c/Users/***/Documents/my-ws/flask/local/lib/python2.7/site-packages/werkzeug/serving.py", line 553, in generate_adhoc_ssl_context
    crypto = _get_openssl_crypto_module()
  File "/mnt/c/Users/***/Documents/my-ws/flask/local/lib/python2.7/site-packages/werkzeug/serving.py", line 84, in _get_openssl_crypto_module
    raise TypeError("Using ad-hoc certificates requires the pyOpenSSL library.")
TypeError: Using ad-hoc certificates requires the pyOpenSSL library.

此错误来自于serving.py文件中的Werkzeug库:

def _get_openssl_crypto_module():
    try:
        from OpenSSL import crypto
    except ImportError:
        raise TypeError("Using ad-hoc certificates requires the pyOpenSSL library.")
    else:
        return crypto

是什么原因导致此问题,以及如何解决此错误?

0 个答案:

没有答案