urequests.get() error related to getaddrinfo
Hello:
I just compiled MicroPython for RPI Pico with WIZNET5k support as described here: https://github.com/Wiznet/RP2040-HAT-MicroPython
Ethernet connects and works.
However urequests gives this error:
request = urequests.get('http://bipes.net.br/test.txt')
Traceback (most recent call last):
File "<stdin>", line 14, in <module>
File "urequests.py", line 116, in get
File "urequests.py", line 55, in request
TypeError: function takes 2 positional arguments but 4 were given
I checked urequests.py and the implementation is:
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
If I change this line to
ai = usocket.getaddrinfo(host, port)
The problem is solved and urequests.get() works!
However, I am uncertain if this would cause other boards/implementations problems.
Can this fix be applied to urequests.py, or it could break other network implementations?
thanks
python-ecosys/urequests: Workaround for faulty getaddrinfo() with ".local" adresses on ESP32.
On the ESP32, socket.getaddrinfo() might return SOCK_DGRAM instead of SOCK_STREAM.
As a HTTP request is always a TCP stream, we don't need to rely on the values returned by getaddrinfo.
This looks like a worthwhile safe change. While normally I'd avoid workarounds in a library for a port-specific issue, as you say a HTTP request should always be set up with SOCK_STREAM so this change makes sense to me.
Merged in a725c420 as part of #500.
@karfas I updated the commit message to match the style of the project but maintained you as the author. Thanks for the change!