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): """