Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fixing Input UnboundLocalError

In my code I’m trying to code a password login loop that will keep requiring a password input until a correct password (defined in an .env file) is given. However, when I run the code below I get an "UnboundLocalError cannot access local variable ‘input’ where it is not associated with a value."
Any ideas?

Here is my code that gives the error:
`from decouple import config

from speech_rec import speak, take_user_input

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

LOGIN=config("SHA-512")

def login():
while True:
input=input("PASSWORD: ")
if input==LOGIN:
break
else:
speak("Try Again")
continue
login()
#rest of code
for i in range(10):
print(i)`

>Solution :

This is most likely because you used one of python’s built-in (input) as a variable name.

import builtins

print("input" in dir(builtins))
#True

Try to give your variable a different name :

from speech_rec import speak, take_user_input

LOGIN=config("SHA-512")

def login():
    while True:
        input_val = input("PASSWORD: ")
        if input_val == LOGIN:
            break
        else:
            speak("Try Again")
        continue
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading