title: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 1: invalid continuation byte
body: <p>I want to convert a byte variable to string. Of course, there are  previous questions related to mine. However, trying to hash in md5() the content of a file this way:   </p>
  
  <pre><code>import hashlib
  with open("C:\\boot.ini","r") as f:
      r=f.read()
  a=hashlib.md5()
  a.update(r.encode('utf8'))
  bytes_data=a.digest()
  print(bytes_data)
  r=type(bytes_data)
  print(r) # &lt;-- Just to be sure, it is in bytes 
  myString=bytes_data.decode(encoding='UTF-8')
  </code></pre>
  
  <p>I got this error:</p>
  
  <pre><code>UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 1: invalid continuation byte
  </code></pre>
  
  <p>I understand the reason of my problem thanks to this <a href="https://stackoverflow.com/questions/5552555/unicodedecodeerror-invalid-continuation-byte">question</a>, however I am dealing with different files to calculate their hash, so I have no control on the bytes, so how can I resolve this problem ?</p>