UnicodeDecodeError错误
我在运行我的Jabber机器人时遇到了这个错误。
File "modules/xmpp/dispatcher.py", line 16, in Process
self.Stream.Parse(data)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc5 in position 32: invalid continuation byte
这个错误出现在代码的第143行:
def Process(self, timeout=0):
""" Check incoming stream for data waiting. If "timeout" is positive - block for as max. this time.
Returns:
1) length of processed data if some data were processed;
2) '0' string if no data were processed but link is alive;
3) 0 (zero) if underlying connection is closed.
Take note that in case of disconnection detect during Process() call
disconnect handlers are called automatically.
"""
for handler in self._cycleHandlers: handler(self)
if len(self._pendingExceptions) > 0:
_pendingException = self._pendingExceptions.pop()
raise _pendingException[0], _pendingException[1], _pendingException[2]
if self._owner.Connection.pending_data(timeout):
try: data=self._owner.Connection.receive()
except IOError: return
self.Stream.Parse(data)
if len(self._pendingExceptions) > 0:
_pendingException = self._pendingExceptions.pop()
raise _pendingException[0], _pendingException[1], _pendingException[2]
if data: return len(data)
return '0' # It means that nothing is received but link is alive.
是不是需要在第16行解码这个data
字符串呢?
请帮我修改代码,解决我的问题……
1 个回答
0
我建议你试试 self.Stream.Parse(data.encode('utf-8'))
这个方法,看看能不能解决问题。