Cannot use urequests library #9773
Replies: 10 comments 3 replies
-
Confusingly.. this is not the official Simple answer though, your ESP32 firmware should already have the urequests library installed, there's no need to install it manually. Longer answer -- the PyPI package namespace is completely disorganised and difficult to navigate, as well as difficult to publish micropython-specific packages to. We no longer support it as a source for installing packages. Thonny is a third-party tool. The official version of urequests is in micropython-lib. You can install packages from micropython-lib using |
Beta Was this translation helpful? Give feedback.
-
Thanks @jimmo
When I try
There are 2 urequests.py files in the Github:
My function does this:
What is wrong with my call? |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your help, I'll have a look at that very soon |
Beta Was this translation helpful? Give feedback.
-
So I used the urllib.urequests - it seems you're the author?
But I don't know how to extract the useful values from the payload. How can I extract the values from the response? Also, when I uncomment the
but I don't know what it means...
Seems bad to me. But I have successfully done the same request using python on my laptop. |
Beta Was this translation helpful? Give feedback.
-
It seems the
|
Beta Was this translation helpful? Give feedback.
-
No I'm just a maintainer.
urllib.urequest is very simple -- it just gives you back the socket containing the HTTP response payload. See https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen I think you can probably do
But just use
This is the HTTP response headers. It's telling you the request was unauthorised (I suspect because the API key was not correctly specified). I'm surprised to see a data payload being specified for a GET request (this would normally only be used for a POST). You should instead be specifiying the query string on the actual URL. The documentation for the API you're using (https://docs.tomorrow.io/reference/get-timelines) provides a Python example on the right hand side that should work: # Copied from https://docs.tomorrow.io/reference/get-timelines
import requests
url = "https://api.tomorrow.io/v4/timelines?location=42.3478%2C%20-71.0466&fields=temperature&units=metric×teps=1h&startTime=now&endTime=nowPlus6h"
headers = {
"accept": "application/json",
"Accept-Encoding": "gzip"
}
response = requests.get(url, headers=headers)
print(response.text) So to adapt that, change the first line to (Where did you get url_escape from, as long as it's generating the escaped |
Beta Was this translation helpful? Give feedback.
-
Thanks, but I don't see where to put the API key and the associated syntax. Many thanks for your help, I'll try this soon and keep you updated. |
Beta Was this translation helpful? Give feedback.
-
Getting better, I now have the response, but can't process it. It's not utf-8, so .decode('utf-8') doesn't work.
and
How can I decode this? Here is the answer from the website (when I paste the url from my micropython code):
|
Beta Was this translation helpful? Give feedback.
-
I found the problem : |
Beta Was this translation helpful? Give feedback.
-
Did you figure out how to solve the OS 202 error |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I'm testing the urequests library, to later launch requests to a weather API.
I installed it with Thonny, and Thonny says (sorry it's in French):
However, when I try this simple skecth:
I immediately get the error message:
I had to copy the urequests.py file from here on the ESP32 flash to bypass this error. But, then I get another error:
Line 25 is :
addr = socket.getaddrinfo(host, int(port))[0][-1]
and the parameters seem correct: host is 'example.com', port is 80.
So, what is going wrong?
Thanks for your help
Beta Was this translation helpful? Give feedback.
All reactions