python 这个脚本有什么错误

What is the mistake in this script in python

如何修复此脚本未显示任何数据:

这是我的代码:

from hashlib import md5
counter = 1
pass_in = input('Enter the md5 hash: ')
pwfile = input('Please enter the passowrd file: ')

try:
    pwfile = open(pwfile,'r')
except:
    print('\nfile not found')
    quit()
for password in pwfile:
    filemd5 = md5()
    filemd5.update(password.strip().encode('utf-8'))
    filemd5.hexdigest()
    print('Trying password number')
    counter += 1

    if pass_in == filemd5:
        print('\n Match Found. \nPassword is: %s' + password)
        break
else:
    print('\n password not found!')

我忘记了什么?

有什么问题?

filemd5.hexdigest() 不会将散列对象转换为字符串,它 returns 是一个字符串。将该行更改为 filemd5 = filemd5.hexdigest().

同样在 print('\n Match Found. \nPassword is: %s' + password) 中将 + 更改为 %

更新:误读了你的问题。亚历克斯的回答是正确的,这有效(更新以显示没有文件的工作代码):

from hashlib import md5
counter = 1
pass_in = input('Enter the md5 hash: ')  # use "5d41402abc4b2a76b9719d911017c592"

for password in ['hello',]:
    filemd5 = md5()
    filemd5.update(password.strip().encode('utf-8'))
    filemd5 = filemd5.hexdigest()  # THIS LINE IS YOUR PROBLEM
    print('Trying password number')
    counter += 1

    if pass_in == filemd5:
        print('\n Match Found. \nPassword is: %s' + password)
        break
else:
    print('\n password not found!')