Skip to content
Advertisement

‘dict’ object has no attribute ‘loads’

Im trying to create a simple key/value store client that accepts input from a text file like this

JavaScript

This is the error I am getting

JavaScript

I currently have the whole thing in a for loop to call the url for each new command but I’m having issues with any input file larger than 1 line. Here is my source, i’m using Python.

JavaScript

Advertisement

Answer

You replaced your json module with the results of the .loads() function:

JavaScript

Don’t do that. Use a different name to store your data. Use data perhaps:

JavaScript

Note that the json module also has a .load() function (no s at the end) that takes a file-like object. Your handle is such an object, so you can use json.load() instead and have that read the response:

JavaScript

Note that I pass in just the handle, we don’t call .read() anymore. I also removed the str() calls; print handles that for us.

Advertisement