This is my code z = (priv.to_string().encode('hex'))
and I got this error:
"AttributeError: 'bytes' object has no attribute 'encode'"
looks like I missed something to show "encode" after the code:
z = (priv.to_string().
Attributes are functions or properties associated with an object of a class. Everything in Python is an object, and all these objects have a class with some attributes. We can access such properties using the . operator. This tutorial will discuss the object has no attribute python error in Python. This error belongs to the AttributeError type.
This error belongs to the AttributeError type. We encounter this error when trying to access an object’s unavailable attribute. For example, the NumPy arrays in Python have an attribute called size that returns the size of the array.
The main cause of the Attributeerror: ‘str’ object has no attribute ‘decode’ is that you are already decoding the decoded strings. Decoding is the process of converting bytes object to str and encoding is the process of converting str to a bytes object. Let’s take an example and understand it.
When ever you get a problems that involves a message such as " 'nonetype' object has no attribute ..." it means the same thing: you have tried to call a method on something that doesn't exist. If you try to do anything with that value, you will get this error. It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen.
Two problems here:
priv.to_string()
(which isn't a built-in method) instead of str(priv)
'hex'
has been removed as an encoding in Python 3, so with str(priv).encode('hex')
you'll get the following error: LookupError: 'hex' is not a text encoding; use codecs.encode()to handle arbitrary codecs
However, since Python 3.5, you can simply do:
priv.hex()
with priv
being a byte string.
Example:
priv = b'test'
print(priv.hex())
Output:
74657374
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With