I have a json
file in the same directory with my app where I have saved some names and passwords. When a user clicks a button, I am trying to retrieve these data and compare it with the input he gave. However, I get an encoding error
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I tried adding errors='ignore'
and change encoding without success.
My login function which opens the json
file:
def login(name,password):
with open('data.json', 'r', encoding='utf-8', errors='ignore') as f:
try:
data = json.loads(f.read())
#data = json.load(f) didnt work also
print(data)
except ValueError: # includes simplejson.decoder.JSONDecodeError
print('Decoding JSON has failed')
return False
f.close()
And this is in my django app
def test(request):
if request.method == 'POST':
given_name = request.POST.get('name', None)
given_password = request.POST.get('pass', None)
# do something with user
if login(given_name, given_password):
about(request)
else:
test_home(request)
....
Json file:
{
"names": [
"test",
],
"passwords": [
"test",
]
}