[New-bugs-announce] [issue17214] urllib.client.HTTPConnection.putrequest encode error

Mi Zou report at bugs.python.org
Sat Feb 16 11:52:39 CET 2013


New submission from Mi Zou:

while urllib following the redirection(302):
urllib.client.HTTPConnection.putrequest raise an error:
#----------------------------------------------------------
  File "D:\Program Files\Python32\lib\http\client.py", line 1004, in _send_request
    self.putrequest(method, url, **skips)
  File "D:\Program Files\Python32\lib\http\client.py", line 868, in putrequest
    self._output(request.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 108-111: ordinal not in range(128)
#----------------------------------------------------------
in the sourcode i found that:
at line 811
def putrequest(self, method, url, skip_host=0,skip_accept_encoding=0)...
the argument url may be a unicode,and it was unquoted..

i think we should replace:
request = '%s %s %s' (method,url,self._http_vsn_str)
with:
import urllib.parse
request = '%s %s %s' (method,urllib.parse.quote(url),self._http_vsn_str)

----------
components: Unicode
messages: 182216
nosy: Mi.Zou, ezio.melotti
priority: normal
severity: normal
status: open
title: urllib.client.HTTPConnection.putrequest encode  error
versions: Python 3.2

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


More information about the New-bugs-announce mailing list