added a dummy useragent in Picture class while fetching image

using URL.
This commit is contained in:
Neeraj Gangwar
2014-03-12 08:00:53 +05:30
parent 15893a3ed0
commit 2f3bd464b8
+5 -1
View File
@@ -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