From 2f3bd464b8bcc0a75460e749c0ec3e8677c91aa5 Mon Sep 17 00:00:00 2001 From: Neeraj Gangwar Date: Wed, 12 Mar 2014 08:00:53 +0530 Subject: [PATCH] added a dummy useragent in Picture class while fetching image using URL. --- skimage/novice/_novice.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/skimage/novice/_novice.py b/skimage/novice/_novice.py index c1f0dce5..a5dbef51 100644 --- a/skimage/novice/_novice.py +++ b/skimage/novice/_novice.py @@ -11,6 +11,7 @@ from skimage.color import color_dict import re import six +import six.moves.urllib from six.moves.urllib_parse import urlparse from six.moves.urllib import request from six.moves.urllib import error @@ -222,7 +223,10 @@ class Picture(object): urlObj = urlparse(path) if (urlObj.scheme == 'http') or (urlObj.scheme == 'https') or (urlObj.scheme == 'ftp') or (urlObj.scheme == 'ftps'): try: - data = urlopen(path).read() + req = request.Request(path) + opener = request.build_opener() + req.add_header('User-Agent', 'Mozilla/5.0') + data = opener.open(req).read() self.array = img_as_ubyte(io.imread(BytesIO(data))) self._format = imghdr.what("", h=data) self._path = path