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.



  • @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


  • Global Moderator

    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



  • 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 is

        def json(self):                                  #line 30
            import ujson                                 #line 31
            return ujson.loads(self.content)             #line 32
    

    I'm using an updated urequests lib including the "encode_basic_auth" function, although I don't think this results in the error.


  • Global Moderator

    I assume you are using urequests here
    The pointer to the objects location is indeed 3f956710, you can use the following to get the result:

    r = requests.post(url, data=data)
    results = r.json()
    print (results)
    

Log in to reply
 

Pycom on Twitter