Solve UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128)

Original link: https://wuzhuti.cn/python-decodeerror-ascii-codec-cant-decode

 import sys reload(sys) sys.setdefaultencoding('utf8')

Confused str and unicode data types in python2.

1. What you need is to have the encoding use the actual encoding instead of ascii

2. For the code that needs str->unicode, you can write the above code in front, and change the str encoding from ascii to utf8 (or gb18030),

3. python3 distinguishes between unicode str and byte arrary, and the default encoding is no longer ascii

Reference: Solve UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128)

The post Addressing UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128) appeared first on Untopic Blog .

This article is reprinted from: https://wuzhuti.cn/python-decodeerror-ascii-codec-cant-decode
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment