Python requests decode using a different charset
<p>I'm using <code>requests</code> to fetch a webpage but the automatically inferred encoding in <code>response.encoding</code> is incorrect. I need to decode the bytes in unicode, but I didn't find an API for this. <code>response.text</code> is Unicode but not the byte array. Any idea?</p>

<p>From <a href="http://docs.python-requests.org/en/master/user/quickstart/#response-content" rel="nofollow">the documentation</a> (emphasis added):</p>

<blockquote>
  <p>When you make a request, Requests makes educated guesses about the
  encoding of the response based on the HTTP headers. The text encoding
  guessed by Requests is used when you access <code>r.text</code>. You can find out
  what encoding Requests is using, and change it, using the <code>r.encoding</code>
  property:</p>

<pre><code>&gt;&gt;&gt; r.encoding
'utf-8'
&gt;&gt;&gt; r.encoding = 'ISO-8859-1'
</code></pre>
  
  <p><strong>If you change the encoding, Requests will use the new value of <code>r.encoding</code> whenever you call <code>r.text</code></strong>. You might want to do this
  in any situation where you can apply special logic to work out what
  the encoding of the content will be. For example, HTTP and XML have
  the ability to specify their encoding in their body. In situations
  like this, you should use <code>r.content</code> to find the encoding, and then
  set <code>r.encoding</code>. This will let you use <code>r.text</code> with the correct
  encoding.</p>
</blockquote>

python python-requests