question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError :__Enter__ error is throwed when using pyopenssl lib 20.01 version

See original GitHub issue

When creating a secure websocket connection(wss) using websocket create_connection() api call in pyopenssl - openssl/ssl.py (20.0.1), AttributeError: enter error is thrown.

Complete error flow is given below :
line 514, in create_connection
websock.connect(url, **options)
line 226, in connect
self.handshake_response = handshake(self.sock, *addrs, **options)
line 76, in handshake
send(sock, header_str)
line 157, in send
return _send()
line 139, in _send
return sock.send(data)
line 1644, in send
with _from_buffer(buf) as data:
AttributeError: enter

Websocket call flow : websocket.create_connection() -> websock.connect->handshake() -> send(sock, header_str) -> sock.send(data)

Surprisingly, when using 19.1.0 of pyopenssl version, there was no such error observed.

Between these 2 versions, send() method in SSL.py file does not have any changes. surprised to see the error when i execute the test case after the update of library.

with _from_buffer(buf) as data:             
    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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
alexcommented, Jan 18, 2021

You’ll need to update to cffi >= 1.12.

0reactions
thiyaneshececommented, Jan 18, 2021

@alex @tiran : Thanks for your feedback. The version cffi -->1.1 is not an explicit version mentioned in requirement.txt file in my py project. However, this version is getting installed due to dependent py module installation, i guess. @alex does cffi version 1.12 is handled to fix the AttributeError: Enter ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: __enter__ in pyopenssl 20.0.1 - Stack Overflow
1), AttributeError: enter error is thrown. Error is pointing to "with statements available in send method of SSL.py file" whereas in 19.1.0 ...
Read more >
Attribute :__Error__ thrown in pyopenssl lib 20.01 : r/learnpython
When creating a secure websocket connection(wss) using websocket create_connection() api call in pyopenssl - openssl/ssl.py (20.0.1), ...
Read more >
The AttributeError: __enter__ Python Error Solved
So, the AttributeError: __enter__ is raised when using a with statement with a class that does not have the __enter__ method. Note, that...
Read more >
AttributeError: module 'lib' has no attribute ... - GitHub
I've used the python:3.7.6-slim-stretch docker image for almost one year. Just today I got this strange issue (with pyOpenSSL==17.5.0): ...
Read more >
openssl - module 'lib' has no attribute ... - Ask Ubuntu
Warning!!! if you are using pyOpenSSL==20.0.1 and find this error when building new container image. Upgrade to pyOpenSSL==22.0.0 could fix ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found