Getting error when using 'with' on socket

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
a-ha
Posts: 21
Joined: Sat Jun 27, 2020 10:42 pm

Getting error when using 'with' on socket

Post by a-ha » Sat Jul 04, 2020 12:11 am

Hello,

I am getting error when using the following construct (which runs fine on pc python):
socket.socket(with socket.AF_INET, socket.SOCK_STREAM) as s:

The error says:
AttributeError: 'socket' object has no attribute '__exit__'

/a-ha

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Getting error when using 'with' on socket

Post by jimmo » Sat Jul 04, 2020 6:54 am

I assume that's supposed to read:

Code: Select all

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
It appears that this isn't supported in MicroPython (on any of the ports that support sockets), but it certainly does seem like a useful thing to support (and at a fairly low implementation cost).

Raised an issue at https://github.com/micropython/micropython/issues/6227

a-ha
Posts: 21
Joined: Sat Jun 27, 2020 10:42 pm

Re: Getting error when using 'with' on socket

Post by a-ha » Sat Jul 04, 2020 7:48 am

Thanks for raising the issue! I appreciated this.

Post Reply