From a48716ad007352d7e79511e91450569811107910 2015-12-21 12:13:53 From: Ben Kasel Date: 2015-12-21 12:13:53 Subject: [PATCH] - Added a fallback to urllib2 for python2 - included urlopen call in a try/except block to avoid crash when no internet connection is available --- diff --git a/IPython/lib/display.py b/IPython/lib/display.py index 4cdedc4..b0176ff 100644 --- a/IPython/lib/display.py +++ b/IPython/lib/display.py @@ -263,8 +263,14 @@ class YouTubeVideo(IFrame): super(YouTubeVideo, self).__init__(src, width, height, **kwargs) def _repr_jpeg_(self): - from urllib import urlopen - return urlopen("https://img.youtube.com/vi/{id}/hqdefault.jpg".format(id=self.id)).read() + try: + from urllib.request import urlopen # Py3 + except ImportError: + from urllib2 import urlopen + try: + return urlopen("https://img.youtube.com/vi/{id}/hqdefault.jpg".format(id=self.id)).read() + except IOError: + return None class VimeoVideo(IFrame): """