Better error message when URL parsing fails

This commit is contained in:
Kovid Goyal 2015-11-03 11:25:46 +05:30
parent 182d9b0d40
commit 5cbd9ef5da

View File

@ -410,7 +410,10 @@ def urlnormalize(href):
"""Convert a URL into normalized form, with all and only URL-unsafe
characters URL quoted.
"""
try:
parts = urlparse(href)
except ValueError as e:
raise ValueError('Failed to parse the URL: %r with underlying error: %s' % (href, as_unicode(e)))
if not parts.scheme or parts.scheme == 'file':
path, frag = urldefrag(href)
parts = ('', '', path, '', '', frag)