Sebastian
Sebastian

Reputation: 141

json.loads() in python behaving weird

I am writing a simple analytic server in python using bottle.

To test it I want to pass a json through the POST method however I have encountered an error and I do not know what is causing it - I am a beginner. The events are as follows:

First of all, this is my code to read the data from the json:

code = request.body.read()
data = json.loads(code)
print data

the expected result is to see a dictionary printed in the terminal.

This works perfectly fine with this json:

{
    "category" : "Videos",
    "action" : "play"
}

but the following one throws a ValueError:

{
    “url” : “www.google.com”,
    “session” : “1234hbnshgrjgcjbhrkfm9834”,
    “agent” : “firefox”,
    “os” : “Windows”,
    “referer” : "null"
}

Upvotes: 0

Views: 107

Answers (1)

propeller
propeller

Reputation: 385

json.loads() assumes straight quotes ("") and not typographical (“”).

Upvotes: 7

Related Questions