'module' object has no attribute 'IPPROTO_UDP'

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

'module' object has no attribute 'IPPROTO_UDP'

Post by jeancf » Thu Oct 06, 2016 8:30 pm

I am writing an app that uses an UDP socket. I saw that the documentation has been updated recently to add the UDP socket functionality that was not present before. However when I call

Code: Select all

socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
I get AttributeError: 'module' object has no attribute 'IPPROTO_UDP' which suggests that the functionality may not be there yet.

Code: Select all

>>> os.uname()
(sysname='esp8266', nodename='esp8266', release='1.5.4(baaeaebb)', version='v1.8.4-dirty on 2016-10-06', machine='ESP module with ESP8266')

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: 'module' object has no attribute 'IPPROTO_UDP'

Post by markxr » Thu Oct 06, 2016 9:55 pm

You can omit the final parameter.

In any case, its default value of 0 is usually the only possible value. In particular, I don't think Micropython supports more than one protocol per type.

The "protocol" parameter is normally only needed for unusual types of sockets, for example, if using raw or udplite sockets.

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

Re: 'module' object has no attribute 'IPPROTO_UDP'

Post by jeancf » Fri Oct 07, 2016 8:07 am

Omitting socket.IPPROTO_UDP works, thanks.

By the way, I am also packing my data in a struct for sending in the datagram. The import of the struct module does not follow this convention:
The modules are available by their u-name, and also by their non-u-name. The non-u-name can be overridden by a file of that name in your package path. For example, import json will first search for a file json.py or directory json and load that package if it is found. If nothing is found, it will fallback to loading the built-in ujson module.
However:

Code: Select all

>>> import struct
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'struct'
>>> import ustruct
>>>

SpotlightKid
Posts: 417
Joined: Wed Apr 08, 2015 5:19 am

Re: 'module' object has no attribute 'IPPROTO_UDP'

Post by SpotlightKid » Sun Oct 09, 2016 6:41 am

Yeah, that bugged me a few times too. time/utime is another offender (on some ports).

Post Reply