Index: Lib/urllib2.py =================================================================== --- Lib/urllib2.py (revision 65739) +++ Lib/urllib2.py (working copy) @@ -560,8 +560,12 @@ newurl = headers.getheaders('uri')[0] else: return - newurl = urlparse.urljoin(req.get_full_url(), newurl) + # fix the broken url and then join with req.get_full_url() + + newurl = urlparse.urljoin(req.get_full_url(), + urlparse.fix_broken(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 Index: Lib/urlparse.py =================================================================== --- Lib/urlparse.py (revision 65739) +++ Lib/urlparse.py (working copy) @@ -40,6 +40,14 @@ _parse_cache.clear() +def fix_broken(url): + """Attempt to fix broken, non-confirming urls. Handle the way the browsers + handle it.""" + scheme, netloc, path, params, query, fragment = urlparse(url) + if not path: path = '/' + fixedurl = urlunparse((scheme, netloc, path, params, query, fragment)) + return fixedurl + class ResultMixin(object): """Shared methods for the parsed result objects."""