UnicodeDecodeError: 'ascii' codec can't decode byte 0x81 in position 1224: ordinal not in range(128)
时间: 2023-10-16 12:21:27 浏览: 43
This error occurs when Python tries to decode a string using the ASCII codec, but it encounters a byte that is not within the range of 128 ASCII characters. In this case, the byte 0x81 (129 in decimal) cannot be decoded by the ASCII codec.
To fix this error, you need to use a different codec that can handle the byte in question. One common solution is to use the UTF-8 codec, which can handle all Unicode characters. You can do this by encoding or decoding the string using the UTF-8 codec explicitly:
```
my_string = b'\x81'
decoded_string = my_string.decode('utf-8')
```
Alternatively, you can set the default encoding to UTF-8 at the beginning of your script:
```
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
```
However, note that changing the default encoding may have unintended consequences, so it is generally recommended to use explicit encoding/decoding instead.