Skip to content

'gbk' codec can't decode byte 0xaf in position 6532: illegal multibyte sequence #1

Description

@ch1st

文本编码问题.
常见的解决办法:
open(‘1.txt’).read().decode(‘gb18030’,’ignore’)

解决办法:
(1)在打开文本的时候,设置其编码的格式.
如:f=open('1.txt','r',encoding='gbk')
(2)如果上一步还是不能解决,那么就是打开的1.txt文本中的一些内容超出了GBK编码的范围.可以选择使用编码更广的'gb1830',
如:f=open('1.txt','r',encoding='gbk')
(3)还是不能解决?那么出现了超出gb1830编码的字符,在后面加个ignore属性
如 :f=open('1.txt','r',encoding='gbk',errors='ignore')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions