属性错误:pyopenssl 20.0.1 中的 __enter__

问题描述

在 pyopenssl 中使用 websocket create_connection() api 调用创建安全的 websocket 连接 (wss) 时 - openssl/ssl.py (20.0.1),AttributeError: enter错误被抛出。

错误指向“在 SSL.py 文件的发送方法中有可用的语句”,而在 19.1.0 pyopenssl 版本中,没有观察到错误

with _from_buffer(buf) as data:
            # check len(buf) instead of len(data) for testability
            if len(buf) > 2147483647:
                raise ValueError(
                    "Cannot send more than 2**31-1 bytes at once."
                )

            result = _lib.SSL_write(self._ssl,data,len(data))
            self._raise_ssl_error(self._ssl,result)

            return result

解决方法

试试pip install pyOpenSSL==19.1.0