title: How to get the position where UnicodeDecodeError occurred?
body: <p>How can I get a position of where did UnicodeDecodeError occurred?
  I found material over <a href="https://docs.python.org/3/library/exceptions.html#UnicodeError" rel="nofollow">here</a> and tried to implement it below. But I just get an error <code>NameError: name 'err' is not defined</code></p>
  
  <p>I searched all over the internet already and here on StackOverflow, but cannot find any hint how to use it. In python docs it says that this particular exception has start attribute, so it must be possible.</p>
  
  <p>Thank you.</p>
  
  <pre><code>    data = buffer + data
      try:
          data = data.decode("utf-8")
      except UnicodeDecodeError:
          #identify where did the error occure?
          #chunk that piece off -&gt; copy troubled piece into buffer and 
          #decode the good one -&gt; 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")
  </code></pre>