for row in reader: UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 1161: illegal multibyte sequence
时间: 2023-10-16 12:18:59 浏览: 37
This error occurs when the CSV file being read contains characters that cannot be decoded using the specified codec (in this case, 'gbk'). The byte 0x99 is an example of such a character.
To fix this error, you need to determine the correct codec for the CSV file. You can try opening the CSV file in a text editor and checking the encoding used in the file properties. Alternatively, you can try different codecs until you find one that works.
Once you have determined the correct codec, you can specify it when opening the CSV file. For example, if the correct codec is 'utf-8', you can open the CSV file like this:
```
import csv
with open('file.csv', newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
# process row
```
Note that the `encoding` parameter is set to 'utf-8' instead of 'gbk', which was causing the error.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)