Page 1 of 1

How can I use urequests module?

Posted: Mon Feb 04, 2019 4:30 pm
by EDW26
I am using ESP32 and it seems to me that there is a memory error. I believe it's due to the library / lib I see when I use the command ampy --port / dev / ttyUSB0 ls. I'm trying to use the following code:
import urequests as re
r = re.get ('site where I get get')
and appears:
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "", line 139, in get
   File "", line 122, in request
   File "", line 66, in request
OSError: [Errno 12] ENOMEM

Re: How can I use urequests module?

Posted: Sun Feb 10, 2019 10:47 pm
by GryKyo
I am having similar memory related problems using the urequests module.

I am very new but surprised myself by getting this to work at all! I am parsing a JSON string which I receive in a MQTT callback function. Within this function I check the topic and do A or B
B is to index a key's value from my dictionary (parsed json) and add it to a Google URL that will write the value to a Google sheets file on Google Drive.
This works once, writes my parsed value to Google Sheets, no problem. The next time I receive the MQTT string I crash with an OS related Memory related error. I have to restart the ESP32 Ctrl+D in the console works to clear the memory issue or it crashes every time.

I don't need the response (which is a screen full of text) so is there a way to disregard or dump the response? Can I use gc.collect() to purge memory or is there a conventional way to avoid memory issues like this?

Any help much appreciated!

Below is the urequest.get and the console error...

Code: Select all

204 response = urequests.get(credentials.google_string + str(log_data))

Traceback (most recent call last):
  File "", line 258, in <module>
  File "", line 255, in <module>
  File "", line 250, in <module>
  File "umqtt/", line 204, in check_msg
  File "umqtt/", line 191, in wait_msg
  File "", line 201, in sub_cb
  File "", line 108, in get
  File "", line 96, in request
  File "", line 60, in request
OSError: [Errno 12] ENOMEM
MicroPython v1.10 on 2019-01-25; ESP32 module with ESP32
Type "help()" for more information.

Re: How can I use urequests module? [SOLVED]

Posted: Mon Feb 11, 2019 10:16 pm
by GryKyo
I spotted the fix for this earlier. The memory issue I was having resulted from leaving the request open.

My code had the call:

Code: Select all

response = urequests.get(credentials.google_string + str(log_data))
... in a mqtt callback used to log something to a google sheets file.

I added:

Code: Select all

... to the end of the function so it is executed after the data is submitted to the google server. All seems good now.