0
如何捕捉python中遇到的unicodedecode錯誤並打印出有問題的字符串是什麼?如何捕獲unicodedecode錯誤python?
即 「......在8位機不能解碼字節XXXX:無效的起始字節」
如何捕捉python中遇到的unicodedecode錯誤並打印出有問題的字符串是什麼?如何捕獲unicodedecode錯誤python?
即 「......在8位機不能解碼字節XXXX:無效的起始字節」
這應該讓你開始:
try:
s = '\xFEFEF'
u = s.decode('utf8')
except UnicodeDecodeError as e:
for p in dir(e):
if not p.startswith('_'):
print '%s=%r' % (p, getattr(e, p))
結果:
args=('utf8', '\xfeFEF', 0, 1, 'invalid start byte')
encoding='utf8'
end=1
message=''
object='\xfeFEF'
reason='invalid start byte'
start=0
帖子整個追蹤。 – Blender