- First of all - detect the file's encoding
from chardet import detect
encoding = lambda x: detect(x)['encoding']
print encoding(line)
- then - convert it to unicode or your default encoding str:
n_line=unicode(line,encoding(line),errors='ignore')
print n_line
print n_line.encode('utf8')