Python AttributeError: ‘str’ object has no attribute ‘decode’

To quote from an existing answer to a similar problem:

You are trying to decode an object that is already decoded. You have a str, there is no need to decode from UTF-8 anymore.

Specific to your question, here is the problem:

    data = str(data)
    print(data.decode('utf-8'))

data = str(data) has already converted data to a string and then you’re trying to decode it again using data.decode(utf-8').

The solution is simple, simply remove the data = str(data) statement (or remove the decode statement and simply do print(data))

Leave a Comment