![](/img/trans.png)
[英]AttributeError: 'tuple' object has no attribute 'encode' python
[英]Python AttributeError: 'tuple' object has no attribute 'encode' in hashlib.encode
我的代碼:
for chars in chain(ALC, product(ALC, repeat=2), product(ALC, repeat=3)):
a = hashlib.md5()
a.update(chars.encode('utf-8'))
print(''.join(chars))
print(a.hexdigest())
它拋出:
Traceback (most recent call last):
File "pyCrack.py", line 18, in <module>
a.update(chars.encode('utf-8'))
AttributeError: 'tuple' object has no attribute 'encode'
完整輸出: http ://pastebin.com/p1rEcn9H tring轉到“ aa”后,似乎引發了錯誤。 我將如何解決這個問題?
您是chain
荷蘭國際集團異類類型在一起,這是頭痛的一原因。
假設ALC
是一個字符串,因此chain
首先會產生字符串中的所有字符。 當它移至product(ALC, repeat=2)
,它開始產生tuple
s,因為這就是product
工作方式。
只需從chain
調用中產生同質類型(即始終產生元組,在需要字符串時join
它們),就可以消除頭痛。
for chars in chain(*[product(ALC, repeat=n) for n in range(1,4)]):
...
a.update(''.join(chars).encode('utf-8'))
您的錯誤是試圖將此元組轉換為utf-8。 嘗試刪除此行“ a.update(chars.encode('utf-8')”
當解釋器顯示“'tuple'對象沒有屬性'encode'時,意味着該對象tuple不支持那樣的轉換。
但是,如果您想轉換所有這些內容,請在程序的第一行中使用#coding:utf-8。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.