Search code examples
pythonif-statementtypeerror

TypeError: expected string or bytes-like object python


I am creating a password validation system. However I have received an error message and i do not understand why or where the error is. I tested these individual pieces of validations on a separate files and they worked okay, however when they were implemented into my actual program, it seems to not work. This is the code responsible for the validation.

#Ensures passwords match and writes the account details to the database
def Checker():
    if re.match(user_password2v2, user_passwordv2):
        match+=1
    else:
        match=match
    if len(user_namev2) > 5 and len(user_passwordv2)>7:#Ensures the username and passwor are of a minimum length
        match+=1
    else:
        match=match
    if re.search(r"\W", user_password2): #Ensures a character is present in the password
        match+=1
    else:
        match=match
    if re.search(r'[0-9]', user_weightv2):#Ensures numbers are used in the weight entry
        match+=1
    else:
        match=match
    if match==4:
        user_information.append(user_namev2)
        user_information.append(user_passwordv2)
        user_information.append(weight)
        Goal_Select()
    if match!=4:
        Error()

Error() should be ran if any of these conditional statements are not met.

user_namev2, user_passwordv2 and user_weightv2 are all variables which are pulled from tkinter entry boxes.

Here is a screenshot of my whole error message. enter image description here


Solution

  • Data type of 'user_passwordv2' doesn't look like to be suitable for re.search.
    How about following code as type conversion?

    re.search(r"\W", str(user_password2))
    #re.search(r"\W", user_password2)