requests.get MicroPython ESP32 INTERNET

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ixbo
Posts: 36
Joined: Wed May 04, 2022 11:12 am
Location: France

requests.get MicroPython ESP32 INTERNET

Post by ixbo » Tue Jun 14, 2022 11:18 am

Hello

I'm trying to use requests.get but it never works
With examples found in internet it's the same....never work
See this example the error message is:

>>> %Run -c $EDITOR_CONTENT
IP MASQ GATEWAY DNS
('192.168.1.33', '255.255.255.0', '192.168.1.254', '32.1.8.97')
Traceback (most recent call last):
File "<stdin>", line 25, in <module>
File "urequests.py", line 108, in get
File "urequests.py", line 53, in request
OSError: -202
>>>


It seems that there is something missing ????
What can I do ?
Thanks very much for any answer !!!!

Code: Select all

import network
import socket
import urequests

SSID = "MyBox"
PASSWORD = "MyPassword"
sta_if = network.WLAN(network.STA_IF)


# ap_if = network.WLAN(network.AP_IF)
# ap_if.active(False)

while not sta_if.isconnected():
    sta_if.active(True)
    print("connection en cours......")
    sta_if.connect(SSID,PASSWORD)
    
if sta_if.isconnected():
    print("     IP               MASQ           GATEWAY        DNS       ")
    print(sta_if.ifconfig())
# attention le DNS est parfois errone !!!!!! "32.1.8.97" au lieu de '192.168.1.254'


	
response = urequests.get('http://jsonplaceholder.typicode.com/albums/1')
print(type(response))

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: requests.get MicroPython ESP32 INTERNET

Post by scruss » Tue Jun 14, 2022 6:06 pm

Which urequests library are you using? There are several libraries called the same, but they're not the same code.

On an ESP32 (SparkFun Thing+) I installed this library: micropython-urequests. I ran your code, inserting my own wifi details.

After one false start ("File "<stdin>", line 17, in <module> OSError: Wifi Internal Error") your code gave me a successful result:

Code: Select all

     IP               MASQ           GATEWAY        DNS       
('192.168.2.145', '255.255.255.0', '192.168.2.1', '192.168.2.1')
<class 'Response'>

ixbo
Posts: 36
Joined: Wed May 04, 2022 11:12 am
Location: France

Re: requests.get MicroPython ESP32 INTERNET

Post by ixbo » Wed Jun 15, 2022 9:23 am

Hello very nice your answer ....

My development board have
==> ESP32-WROVER-B chip

the firmware recommended by my book for this kit is
==> "Firmware (Compiled with IDF 3.x)"
https://github.com/micropython/micropyt ... /tag/v1.14


Why not use this ? :
Firmware
Releases
v1.18 (2022-01-17) .bin [.elf] [.map] [Release notes] (latest)


I don't know witch urequest I have , how to verify ?

I will try your library .....

Thanks very much
best regards

ixbo
Posts: 36
Joined: Wed May 04, 2022 11:12 am
Location: France

Re: requests.get MicroPython ESP32 INTERNET

Post by ixbo » Wed Jun 15, 2022 10:18 am

Hello
I have followed your idea and I have tried with a version witch is not recommended by my book (perhaps to old ? )

Firmware
Releases
v1.18 (2022-01-17) .bin [.elf] [.map] [Release notes] (latest)

Now 'my' program work well I have this result :

>>> %Run -c $EDITOR_CONTENT
IP MASQ GATEWAY DNS
('192.168.1.33', '255.255.255.0', '192.168.1.254', '192.168.1.254')
{
"userId": 1,
"id": 1,
"title": "quidem molestiae enim"
}
>>>


Thank very much for your suggestion !!!!!
best regard

Post Reply