我试图得到一个private_key,我试过这个:
private_key = os.urandom(32).encode('hex')
但它抛出了这个错误:
AttributeError: 'bytes' object has no attribute 'encode'
所以我检查问题并解决了,在Python3x字节中只能解码.然后我将其更改为:
private_key = os.urandom(32).decode('hex')
但现在它抛出了这个错误:
LookupError: 'hex' is not a text encoding; use codecs.decode() to handle arbitrary codecs
我真的不明白为什么.当我在最后一次错误后尝试这个时;
private_key = os.urandom(32).codecs.decode('hex')
它说
AttributeError: ‘bytes’ object has no attribute ‘codecs’
所以我卡住了,我该怎么做才能解决这个问题?我听说这是在Python 2x中工作,但我需要在3x中使用它.