Encoding error when reading url with urllib
<p>When I try to scrape a wikipedia site with a special character in its URL, using urllib.request and Python, I get the following error <code>UnicodeEncodeError: 'ascii' codec can't encode character '\xf8' in position 23: ordinal not in range(128)</code></p>

<p>The code:</p>

<pre><code># -*- coding: utf-8 -*-
import urllib.request as ur

url = "https://no.wikipedia.org/wiki/Jonas_Gahr_StÃ¸re"
r = ur.urlopen(url).read()
</code></pre>

<p>How can I use urllib.request with utf-8 encoding?</p>

<p>Using the <a href="http://stackoverflow.com/a/39229882/2169327">answer from @mousetail</a> I wrote a custom encoder for the characters I needed:</p>

<pre><code>def properEncode(url):
  url = url.replace("Ã¸", "%C3%B8")
  url = url.replace("Ã¥", "%C3%A5")
  url = url.replace("Ã¦", "%C3%A6")
  url = url.replace("Ã", "%C3%98")
  url = url.replace("Ã", "%C3%A5")
  url = url.replace("Ã", "%C3%85")
  return url
</code></pre>

python urllib