I have a dictionry, I don't know it's a nested dict or no. My dictionary is:
my_dict = {"username": "XYZ", "email": "[email protected]",
"location": "Mumbai", "Address": {"Country": "", "City": "", "Street": ""}}
I addedd two values like this:
my_dict['name'] = []
my_dict['number'] = []
and finaly I want to add this dict to Postgresql table. The table is:
My full code is:
my_dict = {"username": "XYZ", "email": "[email protected]",
"location": "Mumbai", "Address": {"Country": "", "City": "", "Street": ""}}
my_dict['name'] = []
my_dict['number'] = []
my_dict["name"] = 'Test'
my_dict["number"] = 30
my_dict["Address"]["Country"] = "Turkey"
my_dict["Address"]["City"] = "Istanbul"
my_dict["Address"]["Street"] = "221sk"
cursor_connection.execute(
'''INSERT into test_table VALUES (%(username)s, %(email)s , %(location)s, %(Country)s , %(City)s , %(Street)s , %(name)s , %(number)s);''', my_dict)
connection_db.commit()
I received this error:
KeyError: 'Country'
I can insert this dict without "Address"'s dictionary but I have a problem with "Address"
