Re: [SOLVED] urequests + redirects
Posted: Mon Jan 18, 2021 7:42 pm
... no idea for urequests + redirects ???
Please see the new forum at
https://forum.micropython.org/
Here, I fixed it for ya:meebox wrote: ↑Tue Dec 01, 2020 11:51 amCan you show me how to use this library in MicroPython? I get error showing me the ussl module doesn't have the SSLContext method.Thanks.mcauser wrote: ↑Fri May 31, 2019 8:42 amIt’s moved here:
https://github.com/pfalcon/micropython- ... /urequests
Code: Select all
$ mpy-cross prequests.py
$ rshell -p /dev/ttyUSB0 cp requests.mpy /pyboard
$ rshell -p /dev/ttyUSB0 repl
>>> import prequests
>>> # note NO trailing slash => triggers a redirect to 'https://chrisarndt.de/impressum/'
>>> r = prequests.get('https://chrisarndt.de/impressum')
>>> print(r.text[:100])
Sure, but even a (preferably strict) subset of httpx - like using features already provided by prequests - would be useful.SpotlightKid wrote: ↑Mon Jan 18, 2021 11:22 pmThis would be unlikely to succeed. httpx has a current LOC of 7553 (LLOC: 3244) and depends on half a dozen other Python modules.
SpotlightKid wrote: ↑Mon Jan 18, 2021 10:59 pmHere, I fixed it for ya:meebox wrote: ↑Tue Dec 01, 2020 11:51 amCan you show me how to use this library in MicroPython? I get error showing me the ussl module doesn't have the SSLContext method.Thanks.mcauser wrote: ↑Fri May 31, 2019 8:42 amIt’s moved here:
https://github.com/pfalcon/micropython- ... /urequests
https://gist.github.com/SpotlightKid/86 ... 41dd269c44
Tested it on an ESP32 with pre-built firmware version esp32-idf3-20210118-unstable-v1.13-274-g49dd9ba1a.bin:
I renamed the module to 'prequests.py', because the current MicroPython firmware for the ESP32 already has an "urequest" module built in, but that does not support redirects and you can't overwrite it with a module file with the same name.
Hth, ChrisCode: Select all
$ mpy-cross prequests.py $ rshell -p /dev/ttyUSB0 cp requests.mpy /pyboard $ rshell -p /dev/ttyUSB0 repl >>> import prequests >>> # note NO trailing slash => triggers a redirect to 'https://chrisarndt.de/impressum/' >>> r = prequests.get('https://chrisarndt.de/impressum') >>> print(r.text[:100])
Hi Chris,SpotlightKid wrote: ↑Mon Jan 18, 2021 10:59 pmHere, I fixed it for ya:meebox wrote: ↑Tue Dec 01, 2020 11:51 amCan you show me how to use this library in MicroPython? I get error showing me the ussl module doesn't have the SSLContext method.Thanks.mcauser wrote: ↑Fri May 31, 2019 8:42 amIt’s moved here:
https://github.com/pfalcon/micropython- ... /urequests
https://gist.github.com/SpotlightKid/86 ... 41dd269c44
Tested it on an ESP32 with pre-built firmware version esp32-idf3-20210118-unstable-v1.13-274-g49dd9ba1a.bin:
I renamed the module to 'prequests.py', because the current MicroPython firmware for the ESP32 already has an "urequest" module built in, but that does not support redirects and you can't overwrite it with a module file with the same name.
Hth, ChrisCode: Select all
$ mpy-cross prequests.py $ rshell -p /dev/ttyUSB0 cp requests.mpy /pyboard $ rshell -p /dev/ttyUSB0 repl >>> import prequests >>> # note NO trailing slash => triggers a redirect to 'https://chrisarndt.de/impressum/' >>> r = prequests.get('https://chrisarndt.de/impressum') >>> print(r.text[:100])