Skip to content

urequests: Compatibility with CPython #379

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

Closed
amotl opened this issue Mar 25, 2020 · 3 comments
Closed

urequests: Compatibility with CPython #379

amotl opened this issue Mar 25, 2020 · 3 comments

Comments

@amotl
Copy link

amotl commented Mar 25, 2020

Hi there,

when invoking the urequests module on CPython, it will croak with

TypeError: %b requires a bytes-like object, or an object that implements __bytes__, not 'str'

when starting to write to the socket stream:

s.write(b"%s /%s HTTP/1.0\r\n" % (method, path))

This has also been reported on adafruit/Adafruit_CircuitPython_Requests#10 and was fixed by adafruit/Adafruit_CircuitPython_Requests#11.

With kind regards,
Andreas.

@mattytrentini
Copy link
Contributor

@andrewleech I think this is also still valid for urequests though I haven't tried it on CPython.

@andrewleech
Copy link
Contributor

andrewleech commented Jul 4, 2022

urequests is currently not really compatible with CPython at all.
For a start, the import would need to handle usocket vs socket, then on cpython there is no socket.write function, only socket.send.

Whether urequests should be compatible with cpython is an interesting discussion, which there could be conveniences to being able to test code in cpython, not much of the micropython-lib codebase would be compatible currently.

Separately to that, the micropython b"%s" % str clearly has an auto-convert which cpython does not support - I guess this is a confusing difference between the platforms, though I feel it's one of many cases micropython is more "tolerant" of things than cpython.

While that patch from circuitpython works to avoid the b"%s" % str error on CPython, it does add extra code (flash&ram) to the module that is not technically needed on micropython currently, so I'm not sure it's really worth adding?

@dpgeorge
Copy link
Member

dpgeorge commented Oct 4, 2022

I don't think it's worth supporting urequests (or any other library in this repo) running under CPython. That would be too restrictive and not allow us to implement things in an efficient way.

@dpgeorge dpgeorge closed this as completed Oct 4, 2022
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

No branches or pull requests

4 participants