Unicodedecodeerror: ' GBK ' codec can ' t decode byte 0xab in position 11126:illegal multibyte

Source: Internet
Author: User

Turn from: http://blog.csdn.net/shijing_0214/article/details/51971734

When using Python, you often encounter the problem of encoding and decoding text, which is a common decoding error as shown in the topic, the following describes the error resolution, the ' GBK ' to ' utf-8 ' also applicable. (1), first when opening the text, set its encoding format, such as: Open (' 1.txt ', encoding= ' GBK ');
(2), if (1) can not be resolved, may be the text appears in some special symbols beyond the GBK coding range, you can choose a wider range of coding ' GB18030 ', such as: Open (' 1.txt ', encoding= ' gb18030 ');
(3), if (2) still can not be resolved, the text appeared in the article even ' GB18030 ' can not be encoded characters, the use of the ' ignore ' attribute to ignore, such as: Open (' 1.txt ', encoding= ' gb18030 ', errors= ' ignore ');
(4) and a common workaround is open (' 1.txt '). Read (). Decode (' gb18030 ', ' ignore ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.