str' object has no attribute 'decode'. Python 3 error?
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.
Simply drop the .decode('utf-8')
part:
header_data = data[1][0][1]
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)
)
AttributeError: 'str' object has no attribute 'decode' in fitting Logistic Regression Model
I tried to upgrade my scikit-learn
using the below command, still, that didn't solve the AttributeError: 'str' object has no attribute 'decode'
issue
pip install scikit-learn -U
Finally, below code snippet solved the issue, add the solver as liblinear
model = LogisticRegression(solver='liblinear')
Does Any one got AttributeError: 'str' object has no attribute 'decode' , while Loading a Keras Saved Model
For me the solution was downgrading the h5py
package (in my case to 2.10.0), apparently putting back only Keras and Tensorflow to the correct versions was not enough.
Related Topics
Download Image with Selenium Python
Python Extending with - Using Super() Python 3 VS Python 2
Number of Days Between 2 Dates, Excluding Weekends
Find Longest Repetitive Sequence in a String
List of Dicts To/From Dict of Lists
Django Aggregation: Summation of Multiplication of Two Fields
How to Handle a Broken Pipe (Sigpipe) in Python
Plotting 3D Polygons in Python-Matplotlib
How to Fix "Importerror: No Module Named ..." Error in Python
Elegant Way to Check If a Nested Key Exists in a Dict
Pandas Create New Column with Count from Groupby
How to Get the Nth Element of a Python List or a Default If Not Available
How to Request a Url in Python and Not Follow Redirects
Why Does Defining _Getitem_ on a Class Make It Iterable in Python
Cast Base Class to Derived Class Python (Or More Pythonic Way of Extending Classes)