Page 1 of 1

'module' object has no attribute 'IPPROTO_UDP'

Posted: Thu Oct 06, 2016 8:30 pm
by jeancf
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')

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

Posted: Thu Oct 06, 2016 9:55 pm
by markxr
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.

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

Posted: Fri Oct 07, 2016 8:07 am
by jeancf
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
>>>

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

Posted: Sun Oct 09, 2016 6:41 am
by SpotlightKid
Yeah, that bugged me a few times too. time/utime is another offender (on some ports).