Bootstrap FreeKB - Resolve "AttributeError str object has no attribute read" with json.load
Resolve "AttributeError str object has no attribute read" with json.load

Updated:

Let's say something like this is being returned.

AttributeError: 'str' object has no attribute 'read'

 

I have run into this error before when I have mistakenly used the variable that contains the full path to my JSON file instead of the variable associated with open the JSON file.

#!/usr/bin/python
import json

json_file = "/path/to/example.json"
 
file = open("/path/to/example.json")
parsed_json = json.load(json_file) <- this should be "file" not "json_file"
file.close()

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter fb2f1f in the box below so that we can be sure you are a human.