diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -648,16 +648,19 @@ class HTTPRedirectHandler(BaseHandler): raise HTTPError( newurl, code, "%s - Redirection to url '%s' is not allowed" % (msg, newurl), headers, fp) if not urlparts.path: urlparts = list(urlparts) urlparts[2] = "/" + if urlparts.fragment: + urlparts = list(urlparts) + urlparts[5] = "" newurl = urlunparse(urlparts) newurl = urljoin(req.full_url, newurl) # XXX Probably want to forget about the state of the current # request, although that might interact poorly with other # handlers that also use handler-specific request attributes new = self.redirect_request(req, fp, code, msg, headers, newurl)