這是我的代碼z = (priv.to_string().encode('hex')) ,我收到了這個錯誤:"AttributeError: 'bytes' object has no attribute 'encode'"看起來我錯過了在代碼之后顯示“編碼”的東西:z = (priv.to_string().
2 回答

萬千封印
TA貢獻1891條經驗 獲得超3個贊
這里有兩個問題:
您正在使用
priv.to_string()
(這不是內置方法)而不是str(priv)
'hex'
已在 Python 3 中作為編碼被刪除,因此str(priv).encode('hex')
您將收到以下錯誤:LookupError: 'hex' is not a text encoding; use codecs.encode()to handle arbitrary codecs
但是,從 Python 3.5 開始,您可以簡單地執行以下操作:
priv.hex()
與priv
作為一個字節的字符串。
例子:
priv = b'test' print(priv.hex())
輸出:
74657374

MMTTMM
TA貢獻1869條經驗 獲得超4個贊
在版本 3.5 之前的 Python3 系統上,您可以from binascii import hexlify
使用hexlify(priv.to_string())
添加回答
舉報
0/150
提交
取消