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
urequests error: IndexError: list index out of range
urequests is working fine with HTTP, but not with HTTPS. I cannot even get the examples working:
`MicroPython v1.9.4-442-g17b512020 on 2018-08-07; ESP32 module with ESP32
Type "help()" for more information.
import urequests
r = urequests.get('https://micropython.org/ks/test.html')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "urequests.py", line 108, in get
File "urequests.py", line 54, in request
IndexError: list index out of range
r = urequests.get('https://www.google.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "urequests.py", line 108, in get
File "urequests.py", line 54, in request
IndexError: list index out of range`
Next line in the "urequests.py" file returns an empty array:
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
If
getaddrinfois not working on your ESP32, there's nothingurequestscan do. It means either your network is not configured properly or theusocketmodule is not working properly.You did connect to a network before trying the examples, didn't you?
Yes, of course, I did successfully connect to the WIFI network. However, I think the strength of the signal is not good enough or it disconnects for some other reason. I have moved the ESP32 closer to the router, and implemented some retries (when it fails, I'm disconnecting and connecting again) and it seems to be working... let's see if it is still working by the end of this week.
You could use the status,
isconnectedandifconfigmethods of yournetwork.WLANinstance to check whether the network is available before usingurequests.Thanks for the feedback. Once fixed the connectivity issues it seems to be working fine, so nothing to do with
urequestslib.Of course it can do. Atleast it can throw relevant exception, so programmer on ESP32 can handle it by reconnect to network. But "List out of range" is terribly wrong for "host not found" error... It looks like error's from Microsoft, they also does not make sense at all.
You're advocating that if a standard library function is not implemented correctly, all users have to deal with that. That's not normally how it works, with good reason, how else would we set up standards. Far fetched analogy: that would be like
1+1not being2and then telling users they have to deal with it themselves :) A correct getaddrinfo either retuns an address, or raises an exception (which is actually how it's currently described in MicroPython's documentation, and which is likely why this PR exists: https://github.com/micropython/micropython/pull/5982), so in this case my opinion is SpotlightKid is correct and it's none of urequests business to deal with this.OSError(-2); // name or service not knownwould be perfect in this scenario. Thanks for referencing https://github.com/micropython/micropython/pull/5982 here, @stinos!OK, that could work if upcall function will return exception instead. Sorry my fault. I rather checking things more in mine code too and since this error being here for 2 years I did not looked for PR which is old 7 days..
Tested with it and that could work
Anyway still some other bug:
Cpython behaviour:
requests.exceptions.MissingSchema: Invalid URL 'nix.cz': No schema supplied. Perhaps you meant http://nix.cz?The positional arg to
getetc. is not calledurlfor nothing."nix.cz"is not a URL.Remember, these libraries are called usomething*, where the u stands for micro. If they included checks for every possible user (developer) error, they wouldn't be micro anymore.
Yes I know. I just goes from linux
wgetcommand where also is "URL" but it supports without http too.. As we using urequests for command "wget" then it appeared too.. But this one I can handle in that our 'wget' command. OkWhat did you actually do to correct this issue?
I am definitely connected to the network and I moved as close as possible to the router.
Did you make some actual code change?
What did you do to actually fix this issue? I am connected to WIFI. I moved closer to the router. Did you implement some retries? Did you implement the retries in software?