"requests" does not handle redirection with relative path correctly
In python-ecosys/requests/requests/init.py:183,
The url redirect can be a relative path, which cause the missing of hostname and protocal at redirecting.
Change HTTP/1.0 to HTTP/1.1 in `requests` Python module
On the Pico W, I'm suddenly having trouble accessing an API that used to be compatible. The issue seems to be the HTTP version, which I documented at https://github.com/orgs/micropython/discussions/15112. As somewhat of a last try, I copied over https://github.com/micropython/micropython-lib/blob/e025c843b60e93689f0f991d753010bb5bd6a722/python-ecosys/requests/requests/init.py into a urequests_2.py, used import urequests_2 as urequests, and simply replaced 1.0 with 1.1:
s.write(b"%s /%s HTTP/1.0\r\n" % (method, path))
with:
s.write(b"%s /%s HTTP/1.1\r\n" % (method, path))
I was able to successfully send data through the API after that. I also wanted to note that I couldn't use the version on master due to ImportError: no module named 'tls', hence the pinned version from above. I have tutorials, videos, and a module within a course dependent on this, so it would be great to have this incorporated into a stable version of Pico W MicroPython if it's feasible.
I think it's a good idea to merge this as-is.
However, it would also be useful to take a look at CircuitPython's request library. It was based on this one but has since had some updates - it'd be good to evaluate if other changes should be integrated too.
See related #844.
It's a shame that HTTP/1.0 is becoming obsolete because it's a nice and simple (and still functional) protocol.
But, yeah, we need to update to use HTTP/1.1. The problem is it's not as simple as changing the
1.0to a1.1. The code also needs to be improved to support chunked responses, at the very least. Also probably need to addAccept-Encoding: identityto the headers to prevent the server from responding with compressed data, which we can't deal with.Note that our
aiohttplibrary does support HTTP/1.1, but it's not really a drop-in replacement forrequests.In summary: let's update to HTTP/1.1 but it needs to be done to the spec, and tested well.
I was banging my head against the wall regarding a similar problem I was having with an API. I appreciate you figuring this out; your solution works perfectly for my needs. Thanks again!