Wie bekomme ich eine Position wo ist UnicodeDecodeError aufgetreten? Ich fand Material über here und versuchte es unten zu implementieren. Aber ich bekomme nur einen Fehler NameError: name 'err' is not defined
Wie bekomme ich die Position, an der UnicodeDecodeError aufgetreten ist?
Ich suchte bereits im Internet und hier auf StackOverflow, kann aber keinen Hinweis finden, wie man es benutzt. In Python-Dokumenten heißt es, dass diese spezielle Ausnahme ein Start-Attribut hat, also muss es möglich sein.
Vielen Dank.
data = buffer + data
try:
data = data.decode("utf-8")
except UnicodeDecodeError:
#identify where did the error occure?
#chunk that piece off -> copy troubled piece into buffer and
#decode the good one -> then go back, receive the next chunk of
#data and concatenate it to the buffer.
buffer = err.data[err.start:]
data = data[0:err.start]
data = data.decode("utf-8")
Voting nah wie trivial, weil die Antwort ein wesentliches Syntaxdetail ist. Könnte immer noch nützlich sein für zukünftige Referenz. –