Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    How to read the response from HTTP post

    Scheduled Pinned Locked Moved Discussion
    5 Posts 3 Posters 79 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      Mao
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • G Offline
        Gijs
        last edited by

        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)
        
        1 Reply Last reply Reply Quote 0
        • M Offline
          Mao
          last edited by

          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.

          S 1 Reply Last reply Reply Quote 0
          • G Offline
            Gijs
            last edited by

            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

            1 Reply Last reply Reply Quote 0
            • S Offline
              SciWax @Mao
              last edited by

              @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

              1 Reply Last reply Reply Quote 0

              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
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom