close

[Solved] AttributeError: ‘list’ object has no attribute ‘encode’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: ‘list’ object has no attribute ‘encode’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: ‘list’ object has no attribute ‘encode’ Error Occurs?

Today I get the following error AttributeError: ‘list’ object has no attribute ‘encode’ in python.

How To Solve AttributeError: ‘list’ object has no attribute ‘encode’ Error ?

  1. How To Solve AttributeError: 'list' object has no attribute 'encode' Error ?

    To Solve AttributeError: 'list' object has no attribute 'encode' Error You need to unicode each element of the list individually
    [x.encode('utf-8') for x in tmp]

  2. AttributeError: 'list' object has no attribute 'encode'

    To Solve AttributeError: 'list' object has no attribute 'encode' Error You need to unicode each element of the list individually
    [x.encode('utf-8') for x in tmp]

Solution 1

You need to do encode on tmp[0], not on tmp.

tmp is not a string. It contains a (Unicode) string.

Try running type(tmp) and print dir(tmp) to see it for yourself.

Solution 2

You need to unicode each element of the list individually

[x.encode('utf-8') for x in tmp]

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read