Hi, this is happening because the structure of the dict is actually:
{
"name": {"name": "SaladShooter"}
}
So as per the line: keyVal = passwordHolder['name'][username] that errors: keyVal = passwordHolder['name'] returns {"name": "SaladShooter"}
Here, in this intermediate dict, the key “SaladShooter” does not exist. So there is a KeyError at line 11
Also further this line passwordHolder['name':username]['password'] will also error out since you cannot slice a dictionary. You can only get keys using the syntax dict["key"]
Fixed code:
Im using this dict structure since i am not sure what you were using: { "user1": "pass1", "user2": "pass2" ... }
import json
import extrapy as e
import os
username = os.environ['REPL_OWNER']
passwordHolder = {}
passwordHolder[username] = ""
while True:
if username in passwordHolder:
f = open('mydata.json')
passwordHolder = json.load(f)
print("[1] Add Password")
print("[2] Show Password")
print("[3] Stop")
addPassword = input()
if addPassword == "1":
e.clear()
print("Enter Password:")
password = input()
passwordHolder[username] = password
e.clear()
if addPassword == "2":
if passwordHolder[username] != "":
e.clear()
print(passwordHolder[username])
else:
e.clear()
print("You Do Not Have A Password")
with open('mydata.json', 'w') as f:
json.dump(passwordHolder, f)
if addPassword == "3":
e.clear()
f.close()
break
else:
print('Invalid User')
break