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

    Invalid json returned by urequests get

    Scheduled Pinned Locked Moved Discussion
    urequestshttp getjson
    7 Posts 4 Posters 1.6k Views 5 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.
    • S Offline
      sprasad
      last edited by

      Hello,
      I was successfully able to 'GET' the contents of a webpage using urequests library. But, on trying to parse it as a json it gives me an error saying ValueError: syntax error in JSON
      Later, I also have to update the values using a 'POST'. Since I'm not able to get a valid json data, I'm not able to use a valid format in POST which is resulting in {"error":"Not Found"}
      How can I proceed with debugging this? Here is my response.text output.

      >>> import urequests as requests
      >>> url = "http://iot4lifts-backend.staging.motius.de/"
      >>> r = requests.get(url)
      >>> print(r.text)
      <input type=button value="Delete All Logs" onclick="location.href='api/delete-logs'" /><br /><table>
      <thead>
          <tr>
              <td>Timestamp</td>
      
              <td>Load Changes</td>
              <td>Bending</td>
              <td>Alarm State</td>
      
              <td>Accelerometer</td>
              <td>Gyroscope</td>
              <td>Magnetometer</td>
      
              <td>GPS-Coordinates</td>
          </tr>
      </thead>
      <tr>
          <td>2018-4-13 11:53:04</td>
      
          <td>0</td>
          <td>0</td>
          <td>-</td>
      
          <td>{"x":0,"y":0,"z":0}</td>
          <td>{"x":0,"y":0,"z":0}</td>
          <td>{"x":0,"y":0,"z":0}</td>
      
          <td><a href="https://www.google.com/maps/search/?api=1&query=0,0" target="_blank">0,0</a></td>
      </tr></table>
      >>> r.json()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "urequests.py", line 32, in json
      ValueError: syntax error in JSON
      
      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @sprasad
        last edited by

        @sprasad
        as you can see you got web page content not json. Then you cannot convert html tags as json.
        Use valid url for your service, if it is your if not then contact with provider.

        think about people first, then computers

        S 1 Reply Last reply Reply Quote 1
        • S Offline
          sprasad @livius
          last edited by

          @livius You were right! GET was implemented to only return html page. Got the correct url where json should be posted and got things working. Thank you for your inputs!

          1 Reply Last reply Reply Quote 0
          • K Offline
            kjm
            last edited by

            When I try this I get File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'get' What exactly is the 'module' object the error refers to?

            1 Reply Last reply Reply Quote 0
            • K Offline
              kjm
              last edited by

              Actually that error was caused by my .py file having the same name as a python library function, my bad. The new error is more serious function takes 2 positional arguments but 4 were given Can any body help me with that error msg?

              1 Reply Last reply Reply Quote 0
              • P Offline
                Paul Thornton
                last edited by

                Can you post your current code (Including the test url if its public). Ill take a look for you.

                K 1 Reply Last reply Reply Quote 0
                • K Offline
                  kjm @Paul Thornton
                  last edited by

                  @paul-thornton I got that sorted by modifying line 53 in urequests as per a suggestion I found online somewhere Paul. I could really use some help withhttps://forum.pycom.io/topic/4014/gpy-in-deep-sleep though.

                  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