← index #8298PR #469
Related · high · value 0.070
QUERY · ISSUE

urequests.get() error related to getaddrinfo

openby rafaelarocaopened 2022-02-13updated 2022-02-13

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

CANDIDATE · PULL REQUEST

python-ecosys/urequests: Workaround for faulty getaddrinfo() with ".local" adresses on ESP32.

closedby karfasopened 2021-11-27updated 2022-07-04

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.

2 comments
andrewleech · 2022-04-04

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.

andrewleech · 2022-07-03

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!

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied