Resolve Self.buf + = '. Join (self.buflist) Unicodedecodeerror: ' UTF8 ' problem

Source: Internet
Author: User

Problem

Return Self.outputBuffer.getvalue ()
  File "C:\Python27\lib\StringIO.py", line 276, in GetValue
    self.buf = "". Join (self.buflist)
unicodedecodeerror: ' UTF8 ' codec can ' t decode byte 0xd0 in position 7:invalid continuation byte

Reason: View GetValue comments

    def getvalue (self): "" "
        Retrieve the entire contents of the" "File" at any time before the
        Stringio object ' s CL OSE () is called.

        The Stringio object can accept either Unicode or 8-bit strings, but mixing the two may
        take some. If both are used, 8-bit strings that cannot is interpreted as
        7-bit ASCII (that use the
        8th bit) would cause a UNIC Odeerror to being raised when GetValue () is
        called.
        "" " Import Chardet
        _complain_ifclosed (self.closed)
        if self.buflist:
            print type (self.buflist)
            Print "Buflist:", self.buflist
            # print "Detect:", Chardet.detect (self.buflist)
            self.buf + = '. Join ( self.buflist)
            print "BUF:", self.buf
            self.buflist = [] return
        SELF.BUF

The writing is very clear:

**the Stringio object can accept either Unicode or 8-bit strings,
But mixing the two may take some care. If both are used, 8-bit
Strings that cannot is interpreted as 7-bit ASCII (that use the
8th bit) 'll cause a unicodeerror to is raised when GetValue ()
Is called.**
Interpreted into Chinese:
Stringio objects can accept Unicode or 8-bit strings, but mixing the two may require careful

Solution:
Delete the following related statements

Print "__file__:", __file__
print "__file__:", Chardet.detect (__file__)

Because __file__ is the ' GB2312 ' code.

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.