lundi 10 mai 2021

Cannot generate random password with string module in python

def generatePass():
    global Symbol
    if Symbol:
        pass_len = entry.get()
        temp = string.ascii_letters + string.digits
        password = random.sample(temp,pass_len)
        text.delete(1.0, END)
        text.insert(INSERT, password)
        print(password)
    else:
        pass_len = entry.get()
        temp = string.ascii_letters + string.digits + string.punctuation
        password = random.sample(temp,pass_len)
        text.delete(1.0, END)
        text.insert(INSERT, password)
        print(password)

When I run this code it said TypeError: '<=' not supported between instances of 'int' and 'str'. The error is given from password = random.sample(temp,pass_len) I tried fixing this error by add int() before random.sample(temp,pass_len) but it didn't work. Any solution?




Aucun commentaire:

Enregistrer un commentaire