搜尋

首頁  >  問答  >  主體

Python3 在使用traceback.format_exc()的时候遇到 UnicodeDecodeError

RT,怎么回事?

try:
    xxxxx
except:
    import traceback
    ret['response-head']['msg'] = traceback.format_exc(1)
KeyError: '56 '

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python3.3/lib/python3.3/site-packages/Django-1.5-py3.3.egg/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "./videoDetectWebsite/views/index.py", line 113, in api
  File "/usr/local/python3.3/lib/python3.3/traceback.py", line 270, in format_exc
    format_exception(etype, value, tb, limit, chain))
  File "/usr/local/python3.3/lib/python3.3/traceback.py", line 187, in format_exception
    list.extend(format_tb(tb, limit))
  File "/usr/local/python3.3/lib/python3.3/traceback.py", line 75, in format_tb
    return format_list(extract_tb(tb, limit))
  File "/usr/local/python3.3/lib/python3.3/traceback.py", line 100, in extract_tb
    line = linecache.getline(filename, lineno, f.f_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 15, in getline
    lines = getlines(filename, module_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 41, in getlines
    return updatecache(filename, module_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 127, in updatecache
    lines = fp.readlines()
  File "/usr/local/python3.3/lib/python3.3/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position 205: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 936, in emit
    msg = self.format(record)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 807, in format
    return fmt.format(record)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 554, in format
    record.exc_text = self.formatException(record.exc_info)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 504, in formatException
    traceback.print_exception(ei[0], ei[1], tb, None, sio)
  File "/usr/local/python3.3/lib/python3.3/traceback.py", line 162, in print_exception
    print_tb(tb, limit, file)
  File "/usr/local/python3.3/lib/python3.3/traceback.py", line 68, in print_tb
    line = linecache.getline(filename, lineno, f.f_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 15, in getline
    lines = getlines(filename, module_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 41, in getlines
    return updatecache(filename, module_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 127, in updatecache
    lines = fp.readlines()
  File "/usr/local/python3.3/lib/python3.3/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position 205: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python3.3/lib/python3.3/site-packages/Django-1.5-py3.3.egg/django/core/handlers/wsgi.py", line 255, in __call__
    response = self.get_response(request)
  File "/usr/local/python3.3/lib/python3.3/site-packages/Django-1.5-py3.3.egg/django/core/handlers/base.py", line 178, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/usr/local/python3.3/lib/python3.3/site-packages/Django-1.5-py3.3.egg/django/core/handlers/base.py", line 212, in handle_uncaught_exception
    'request': request
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 1260, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 1366, in _log
    self.handle(record)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 1376, in handle
    self.callHandlers(record)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 1438, in callHandlers
    hdlr.handle(record)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 832, in handle
    self.emit(record)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 944, in emit
    self.handleError(record)
  File "/usr/local/python3.3/lib/python3.3/logging/__init__.py", line 885, in handleError
    None, sys.stderr)
  File "/usr/local/python3.3/lib/python3.3/traceback.py", line 162, in print_exception
    print_tb(tb, limit, file)
  File "/usr/local/python3.3/lib/python3.3/traceback.py", line 68, in print_tb
    line = linecache.getline(filename, lineno, f.f_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 15, in getline
    lines = getlines(filename, module_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 41, in getlines
    return updatecache(filename, module_globals)
  File "/usr/local/python3.3/lib/python3.3/linecache.py", line 127, in updatecache
    lines = fp.readlines()
  File "/usr/local/python3.3/lib/python3.3/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position 205: invalid start byte
[pid: 12907|app: 0|req: 1/1] 118.192.22.212 () {44 vars in 733 bytes} [Sat Jun  8 08:13:39 2013] POST /api/huohuaId2Url => generated 0 bytes in 550 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
巴扎黑巴扎黑2804 天前944

全部回覆(1)我來回復

  • PHP中文网

    PHP中文网2017-04-17 11:32:05

    哦看到了是 Django。做一個能夠復現問題的最小範例,貼他們的 issue tracker / bugzilla / whatever 上去。

    回覆
    0
  • 取消回覆