Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change HTTP/1.0 to HTTP/1.1 in requests Python module #861

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sgbaird
Copy link

@sgbaird sgbaird commented May 24, 2024

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.

@mattytrentini
Copy link
Sponsor Contributor

mattytrentini commented May 25, 2024

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.

@dpgeorge
Copy link
Member

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.0 to a 1.1. The code also needs to be improved to support chunked responses, at the very least. Also probably need to add Accept-Encoding: identity to the headers to prevent the server from responding with compressed data, which we can't deal with.

Note that our aiohttp library does support HTTP/1.1, but it's not really a drop-in replacement for requests.

In summary: let's update to HTTP/1.1 but it needs to be done to the spec, and tested well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants