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 = ""
    >>> r = requests.get(url)
    >>> print(r.text)
    <input type=button value="Delete All Logs" onclick="location.href='api/delete-logs'" /><br /><table>
            <td>Load Changes</td>
            <td>Alarm State</td>
        <td>2018-4-13 11:53:04</td>
        <td><a href=",0" target="_blank">0,0</a></td>
    >>> r.json()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "", 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 with 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