How do I receive data, like numbers and text, through the GET method in MicroPython? #10981
-
Recently, I have been working on a project using an ESP32 and MicroPython. However, I have not found much documentation concerning MicroPython's urllib.urequest or the sockets library, specifically on how to go about transmitting data through an HTML form via the GET method and receiving it as a variable. It's in essence the same problem as this one How can I get the named parameters from a URL using Flask? but because that solution only works for the Flask module, it does not answer my question on doing the same with micropython. Retrieving form parameters via GET in regular Python is as simple as requesting the arguments using Flask's request library, like so: value = request.args['argument'] And then sending a request in HTML: <form action="/" method="get" target="_blank">
<label for="argument">Argument:</label>
<input type="text" id="argument" name="argument"><br><br>
<input type="submit" value="Submit">
</form> Which then outputs something like this:
However, there is no such attribute in MicroPython's urllib.urequest nor in the sockets library. Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'args' Does anyone know how to get the results from micropython? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Greetings, I'm new to MicroPython, but I am trying to help out folks since so many have helped me out. So my apologies if my answers are a bit rough. I'm a little confused by your post; I think you are talking about two different types of requests. the Is your ESP32 the client, the server, or both in your question? If you are the server, and you are using sockets, you should be able to parse them manually, that is what I've done in the past. Is your code online anywhere? |
Beta Was this translation helpful? Give feedback.
-
So like I said before, I just parse it myself. There may be a library out there that can do it, but here is some of my code that I've adapted to your example quick.
and here is an example of the response I get and the params I can use:
|
Beta Was this translation helpful? Give feedback.
-
If you're looking to set time on the esp32 from the date returned returned by a server you can just grab the date from a server reply in urequests by inserting a line after l=s.readline() in the urequests lib
saves all that pfaffing about with ntp servers. |
Beta Was this translation helpful? Give feedback.
So like I said before, I just parse it myself. There may be a library out there that can do it, but here is some of my code that I've adapted to your example quick.