[issue17214] http.client.HTTPConnection.putrequest encode error

Vajrasky Kok report at bugs.python.org
Thu Jul 18 17:10:43 CEST 2013


Vajrasky Kok added the comment:

I have no problem if this ticket is classified as "won't fix".

I am writing this for the confused souls who want to use urllib to access url containing non-ascii characters:

import urllib.request
from urllib.parse import quote
url = "http://www.libon.it/ricerca/7817940/3499155443/dettaglio/3102314/Onkel-Oswald-und-der-Sudan-Käfer/order/date_desc"

req = urllib.request.Request(url)
try:
    req.selector.encode('ascii')
except UnicodeEncodeError:
    req.selector = quote(req.selector)
response = urllib.request.urlopen(req, timeout=30)
the_page = response.read().decode('utf-8')
print(the_page)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17214>
_______________________________________


More information about the Python-bugs-list mailing list