>>> data_str="some data string"
>>> data_str.decode("UTF-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?
You will get this error when you try to decode a string in Python which is already decoded.
Remember that the process of decoding is to convert the bytes to a string object. The bytes are encoded in a specific character encoding, such as UTF-8 or ASCII. When we do decoding these bytes are transformed into a string using the appropriate character encoding.
Example:byte_data = b'Some data as bytes'
string_data = byte_data.decode('utf-8')
Fix:
The solution is simple, you do not need to use decode("UTF-8") or you meant to make the string as a byte string.

>>> data_str=b"some data string"
>>> data_str.decode("UTF-8")
'some data string'
>>>
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!