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>If using a library is an option, I would suggest the awesome <a href="http://docs.python-requests.org/" rel="nofollow">requests</a></p>

<pre><code># -*- coding: utf-8 -*-
import requests
r = requests.get('https://no.wikipedia.org/wiki/Jonas_Gahr_StÃ¸re')
print(r.text)
</code></pre>

python urllib