'gbk' codec can't decode byte 0xaa in position 4294: illegal multibyte sequence

使用python的时候经常会遇到文本的编码与解码问题,其中很常见的一种解码错误如题目所示,下面介绍该错误的解决方法,将‘gbk’换成‘utf-8’也适用。
(1)、首先在打开文本的时候,设置其编码格式,如:open(‘1.txt’,encoding=’gbk’);
(2)、若(1)不能解决,可能是文本中出现的一些特殊符号超出了gbk的编码范围,可以选择编码范围更广的‘gb18030’,如:open(‘1.txt’,encoding=’gb18030’);
(3)、若(2)仍不能解决,说明文中出现了连‘gb18030’也无法编码的字符,可以使用‘ignore’属性进行忽略,如:open(‘1.txt’,encoding=’gb18030’,errors=‘ignore’);
(4)、还有一种常见解决方法为open(‘1.txt’).read().decode(‘gb18030’,’ignore’)
---------------------
原文:https://blog.csdn.net/shijing_0214/article/details/51971734

'gbk' codec can't decode byte 0xaa in position 4294: illegal multibyte sequence

原文地址:https://www.cnblogs.com/Magicn/p/10263853.html

时间: 2024-10-11 07:01:13

'gbk' codec can't decode byte 0xaa in position 4294: illegal multibyte sequence的相关文章

python打开文件查询字符串时报UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 19: illegal multibyte sequence错误

当这样打开时报错了 lines = open(path).readlines() open(path).close() for line in lines: idx1 = line.find('检测到的 SN 为:') idx1 += len('检测到的 SN 为:') idx2 = line.find(' 或许与您申请的SN不符,请联系技术提供方',idx1) responsetimestr = line[idx1:idx2] rts = responsetimestr   UnicodeDe

UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 9: illegal multibyte sequence

上面是遇到的错误,本来想完成读文件,再写入另一文件的.但是在 fp.read() 时,一直遇到上面的错误,经过各种百度,google, 还有神奇的 stackoverflow 才知道是字符流的问题. 知道问题所在,还是没有解决,又苦苦搜索,终于在 stackoverflow 上找到灵感,可以把 open 的方式变为 二进制,也就是下面代码里的 open(filename,'rb'), 这下好了,至少后面的read() 可以通过. 再之后就产生了以下代码,发现问题的路真心不好走,在此mark 下.

python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence

python读写txt文件转化成excel文件 python读取文件时提示"UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence" 解决办法1. FILE_OBJECT= open('order.log','r', encoding='UTF-8') 解决办法2. FILE_OBJECT= open('order.log','rb') pyth

UnicodeDecodeError: 'gbk' codec can't decode byte 0xbc in position 21: illegal multibyte sequence

Save the txt with UTF format and then open the file with f1 = open(path, encoding = 'utf') UnicodeDecodeError: 'gbk' codec can't decode byte 0xbc in position 21: illegal multibyte sequence

Python文件读取报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 9: illegal multibyte sequence

源代码: fo = open("***.csv","r") 报错: 解决方案: fo = open("***.csv","r",encoding='UTF-8') Python文件读取报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 9: illegal multibyte sequence 原文地址:https://www.cnblog

pyquery 读取HTML报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 78: illegal multibyte sequence

今天学习pyquery 读取HTML文件时,报错 这是字符编码错误,读取的时候不能读取gbk格式的字符 然后打开HTML文档,发现里面有中文字符,将中文字符去掉之后就可以执行了. pyquery 读取HTML报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 78: illegal multibyte sequence 原文地址:https://www.cnblogs.com/zll20153246/p/963

python 读取文件时报错: UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence python读取文件时提示UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence 解决办法: FILE_OBJECT= open('order.log','r'

python执行报错“UnicodeDecodeError: 'gbk' codec can't decode byte 0xa1 in position 110: illegal multibyte sequence”

执行如下程序报错 import pytest @pytest.fixture() def user(): print("获取用户名") a = "zt" return a def test_1(user): assert user == "zt" if __name__ == "__main__": pytest.main(["-s","test_fixture1.py"]) Testi

Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence

Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence 解决办法: 在语句open(sFileName,newline='')中,增加encoding='UTF-8',如下: open(sFileName,newline='',encoding='UTF-8') Python读取CSV文件,报错:UnicodeDecode