Click here to Skip to main content
15,355,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to make a sign-in/login system using replit.com's db library, i keep running into an issue where i get a TypeError saying that 'NoneType' object is not subscriptable

Code of issue:

Python
def signup():
	username = str(input('Username> '))
	password = str(input('Password> '))
	try:
		if db[username]:
			print('username taken!')
	except KeyError:
			db[username] = {
				'Username':username,
				'Password':password,
				'Money':50,
				'TotalBetting':0,
				'TotalProfit':0,
			}
			print(db[str(username)])


Error:

Traceback (most recent call last):
  File "main.py", line 45 in <module>
    signup()
  File "main.py", line 18, in signup
    if db[username]:
TypeError: 'NoneType' object is not subscriptable

I dont know if it is assigning username/password as the input function, even though it should be returning a string

What I have tried:

I have tried to rework the code multiple times, didnt work
Looked everywhere for an answer but nothing had the same issue that i was looking for
Posted
Comments
Richard MacCutchan 20-May-22 3:08am
   
The message is telling you that you have not initialised db to refer to an actual array.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900