Ali Ali - 2 months ago 15
Python Question

AttributeError: 'tuple' object has no attribute 'decode' while trying to decode string

I am running this code on Python 3. I encoded the data using

while accepting from the server. But now I want to
it in order make it human readable.

All1 = soup.findAll('tag_name', class_='class_name')
All2 = "".join([p.text for p in All1])
str = "1",All2.encode('utf_8')

But it is giving the following error:

AttributeError: 'tuple' object has no attribute 'decode'

How can I decode it ?


str (don't name your variables after built-in functions, by the way) is a tuple, not a string.

str = "1",All2.encode('utf_8')

This is equivalent to the more readable:

str = ("1", All2.encode('utf_8'))

I don't know what you need the "1" for, but you might try this:

num, my_string = '1', All2.encode('utf_8')

And then decode the string: