title: Why do I get 'UnicodeEncodeError'?
body: <p>I have this code (warn: on URL content for adults only!)</p>
  
  <pre><code># Encoding: UTF-8
  
  import re
  import requests
  # import chardet
  
  html = requests.get('http://klonedaset.org/news.php?sid=51854&amp;bn=luRsF2aAa6eV63nU71Jm&amp;ad=0&amp;ref=&amp;pt=&amp;cookie=null&amp;cls=null').text
  text = re.findall('target=_blank id=.*?&gt;(.*?)&lt;/a&gt;', html)[0]
  # print chardet.detect(text) return this "{'confidence': 0.9599621544520228, 'encoding': 'windows-1251'}"
  
  open('file12.txt', 'a').write(text)
  </code></pre>
  
  <p>And I get this error on the last line (where I write in the file)</p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) 
  </code></pre>
  
  <p>I trying doing such as this </p>
  
  <pre><code>html = html.decode(windows-1251').encode('UTF-8')
  </code></pre>
  
  <p>But it doesn't work. I must write to the file in UTF-8! </p>