[NEW] Add url to urllib exceptions
@@ -18,6 +18,7 @@ from functools import partial
from operator import itemgetter
from os import O_NONBLOCK, path as p
from io import BytesIO, StringIO, TextIOBase
+from urllib.error import HTTPError, URLError
from six.moves.urllib.request import urlopen
@@ -205,6 +206,11 @@ class fetch(TextIOBase):
r = urlopen(url, context=self.context, timeout=self.timeout)
except TypeError:
r = urlopen(url, timeout=self.timeout)
+ except HTTPError as e:
+ msg = '{} returned {}: {}'
+ raise URLError(msg.format(url, e.code, e.reason))
+ except URLError as e:
+ raise URLError('{}: {}'.format(url, e.reason))
text = r.read() if self.cache_type else None
