diff --git a/Lib/http/client.py b/Lib/http/client.py --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -263,6 +263,7 @@ headers.append(line) if line in (b'\r\n', b'\n', b''): break + print(headers) hstring = b''.join(headers).decode('iso-8859-1') return email.parser.Parser(_class=_class).parsestr(hstring) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -652,11 +652,13 @@ "%s - Redirection to url '%s' is not allowed" % (msg, newurl), headers, fp) - if not urlparts.path: - urlparts = list(urlparts) - urlparts[2] = "/" - newurl = urlunparse(urlparts) - + urlpartslist = list(urlparts) + path = urlparts.path if urlpaths.path else "/" + # parse_headers() decodes from iso-8859-1 and unquotes, undo damage + path = urlparts.path.encode("iso-8859-1") + urlpartslist[2] = quote(path) + + newurl = urlunparse(urlpartslist) newurl = urljoin(req.full_url, newurl) # XXX Probably want to forget about the state of the current