Python Mastery module 9.9

Followed Mosh exactly on Windows PC n get attribute Error: ‘str’ object has no attribute ‘values’

I modified code to use print() to try to narrow down cause of error… Believe it has to do with the json.loads() method

Solved my own problem! Issue had to do with how dictionary was structured!
I had a key called movies within the movies.json file and this is where the movie sets were nested.
solution:

movies = json.loads(Path(“movies.json”).read_text())
with sqlite3.connect(“movies.db”) as sq_conn:
command = “INSERT INTO movies VALUES(?,?,?)”
for m in movies[‘movies’]:
sq_conn.execute(command, tuple(m.values()))

1 Like