Page 2 of 3

Re: [SOLVED] urequests + redirects

Posted: Mon Jan 18, 2021 7:42 pm
by dzairo
... no idea for urequests + redirects ???

Re: [SOLVED] urequests + redirects

Posted: Mon Jan 18, 2021 10:59 pm
by SpotlightKid
meebox wrote:
Tue Dec 01, 2020 11:51 am
mcauser wrote:
Fri May 31, 2019 8:42 am
It’s moved here:
https://github.com/pfalcon/micropython- ... /urequests
Can 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.
Here, I fixed it for ya:

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.

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])
Hth, Chris

Re: [SOLVED] urequests + redirects

Posted: Mon Jan 18, 2021 11:22 pm
by SpotlightKid
mattyt wrote:
Wed Dec 02, 2020 1:17 am
Don't suppose anyone is keen to port - or write a subset - of httpx to MicroPython?
This would be unlikely to succeed. httpx has a current LOC of 7553 (LLOC: 3244) and depends on half a dozen other Python modules.

Re: [SOLVED] urequests + redirects

Posted: Mon Jan 18, 2021 11:32 pm
by mattyt
SpotlightKid wrote:
Mon Jan 18, 2021 11:22 pm
mattyt wrote:
Wed Dec 02, 2020 1:17 am
Don't suppose anyone is keen to port - or write a subset - of httpx to MicroPython?
This would be unlikely to succeed. httpx has a current LOC of 7553 (LLOC: 3244) and depends on half a dozen other Python modules.
Sure, but even a (preferably strict) subset of httpx - like using features already provided by prequests - would be useful.

It may be worth noting that the requests and httpx modules are in roughly the same ballpark of size.

Re: [SOLVED] urequests + redirects

Posted: Mon Jan 18, 2021 11:41 pm
by SpotlightKid
Yeah, and neither would fit on an MicroPython board without serious reworking ("urequest.py" has not much in common with "requests" except the name and the module-level function names). At which point it is easier to (re-)implement the features you need from them.

Feel free to prove me wrong by porting it. ;)

Re: [SOLVED] urequests + redirects

Posted: Tue Jan 19, 2021 4:26 pm
by dzairo
Thanks, I try it tomorrow..
I want send data to google spreadsheet.. .

Re: [SOLVED] urequests + redirects

Posted: Tue Jan 19, 2021 6:47 pm
by dzairo
Super ... yes .. working .. perfect .. super .. thanks ..

Send data to Google SpreadSheet and return back answer from server .

thanks ..

Re: [SOLVED] urequests + redirects

Posted: Wed Jan 20, 2021 7:52 am
by meebox
I'll try it.Thanks.
SpotlightKid wrote:
Mon Jan 18, 2021 10:59 pm
meebox wrote:
Tue Dec 01, 2020 11:51 am
mcauser wrote:
Fri May 31, 2019 8:42 am
It’s moved here:
https://github.com/pfalcon/micropython- ... /urequests
Can 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.
Here, I fixed it for ya:

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.

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])
Hth, Chris

Re: [SOLVED] urequests + redirects

Posted: Sun Apr 04, 2021 9:49 pm
by VicLuna
HI
I installed the library that you mention.
I renamed
and I got an error OSError: -202

I could not test with esp32-idf3-20210118-unstable-v1.13-274-g49dd9ba1a.bin because it's not available,
so I tested with esp32-idf4-20210202-v1.14.bin

May you help me?
I'm trying to get data from a Google Sheet Web API, that already works with postman.

Thanks

Re: [SOLVED] urequests + redirects

Posted: Tue Sep 14, 2021 4:40 pm
by ani-rudh
SpotlightKid wrote:
Mon Jan 18, 2021 10:59 pm
meebox wrote:
Tue Dec 01, 2020 11:51 am
mcauser wrote:
Fri May 31, 2019 8:42 am
It’s moved here:
https://github.com/pfalcon/micropython- ... /urequests
Can 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.
Here, I fixed it for ya:

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.

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])
Hth, Chris
Hi Chris,
I am on windows 10 and I want to copy the requests lib to my esp32 cam board.
I tried using your solution and copy the .mpy file to the board. But, I am not able to use the copy function properly since it seems the files are printed as copied to the same directory as I specify as source instead of the device.