Invalid json returned by urequests get



  • 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
    


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



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



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



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



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



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


Log in to reply
 

Pycom on Twitter