AttributeError: type object 'socket' has no attribute 'timeout'

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
jeancf
Posts: 8
Joined: Fri Apr 29, 2016 9:05 am

AttributeError: type object 'socket' has no attribute 'timeout'

Post by jeancf » Wed Jan 04, 2017 7:41 pm

I am running micropython 1.8.6 on a Wemos D1 mini v1.

I have an application that uses UDP sockets. It runs but I have a problem catching `timeout` exceptions. This code:

Code: Select all

from machine import UART
import socket

uart = UART(0, 115200)

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(2.0)
s.bind(("", 9999))
try:
    s.receive(10)
except socket.timeout:
    uart.write("Exception caught\n")
throws:

Code: Select all

Traceback (most recent call last):
  File "main.py", line 12, in <module>
AttributeError: type object 'socket' has no attribute 'timeout'
Instead of catching the exception.

Am I doing something wrong?

User avatar
ernitron
Posts: 89
Joined: Fri Jun 03, 2016 5:53 pm
Location: The Netherlands

Re: AttributeError: type object 'socket' has no attribute 'timeout'

Post by ernitron » Wed Jan 04, 2017 8:55 pm

jeancf wrote: Am I doing something wrong?
No I guess, not. I had the same problem. Looks like socket.timeout is not implemented (or is not the correct exception that upython throws on timeout). I simply catch everything and that worked for me.

Code: Select all

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(2.0)
s.bind(("", 9999))
try:
    s.receive(10)
except:
    uart.write("Exception caught\n")

User avatar
jeancf
Posts: 8
Joined: Fri Apr 29, 2016 9:05 am

Re: AttributeError: type object 'socket' has no attribute 'timeout'

Post by jeancf » Sat Jan 07, 2017 10:07 am

Thanks for the workaround. I can use it for now. I will file a bug.

/~JC

User avatar
jeancf
Posts: 8
Joined: Fri Apr 29, 2016 9:05 am

Re: AttributeError: type object 'socket' has no attribute 'timeout'

Post by jeancf » Tue Jan 17, 2017 2:50 pm


Post Reply