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.