How to read the response from HTTP post
-
My HTTP post returns me
<Response object at 3f956710>.What's the meaning of this? I suppose the response has been stored at 3f956710.
How can I read the response?
Thank you.
-
I assume you are using
urequestshere
The pointer to the objects location is indeed3f956710, you can use the following to get the result:r = requests.post(url, data=data) results = r.json() print (results) -
Hi Gijs,
It returns me the following error.
Traceback (most recent call last): File "main.py", line 40, in <module> File "/flash/lib/urequests.py", line 32, in json ValueError: syntax error in JSON Pycom MicroPython 1.20.2.r1 [v1.11-a5aa0b8] on 2020-09-09; GPy with ESP32 Type "help()" for more information.Line 40 of my code is
HTTP_res = r.json()
Line 32 of my urequests lib isdef json(self): #line 30 import ujson #line 31 return ujson.loads(self.content) #line 32I'm using an updated urequests lib including the "encode_basic_auth" function, although I don't think this results in the error.
-
Right, that means the response is not in a JSON format. You can do without the line as well. r should contain the response from the request and you can also use
r.text() r.content()Gijs
-
@Mao said in How to read the response from HTTP post:
I'm using an updated urequests lib including the "encode_basic_auth" function, although I don't think this results in the error.
Hello Mao, can you tell me, where you found a urequests lib with a function for basic auth, which works? I need that for my project.
Kind regards,
SciWax
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login