这是我的代码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
	提交
		取消
	