From d1b9f4262fff74a5bdc6197574d6cc9e68a1c98b Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Thu, 28 Mar 2019 12:02:15 -0400 Subject: [PATCH] Fix pywwt on `notebook >=5.7.6` Version 5.7.6 of the Jupyter notebook module adds a new security feature related to the HTTP content types (https://github.com/jupyter/notebook/issues/4467#issuecomment-471353499). It breaks pywwt because pywwt has not been returning valid MIME types (AKA content types) from its internal Jupyter server. From looking at the main `notebook` implementation, it seems that the correct approach is to use the `mimetypes` module to get the right value to put in the Content-Type header, so let's go ahead and do that. Closes #191. --- pywwt/jupyter_server.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pywwt/jupyter_server.py b/pywwt/jupyter_server.py index 3722f9c7..49619e93 100644 --- a/pywwt/jupyter_server.py +++ b/pywwt/jupyter_server.py @@ -1,5 +1,6 @@ import os import json +import mimetypes from hashlib import md5 from tornado import web from notebook.utils import url_path_join @@ -33,6 +34,9 @@ def get(self, filename): else: raise web.HTTPError(404) + # Do our best to set an appropriate Content-Type. + self.set_header('Content-Type', mimetypes.guess_type(filename)[0]) + with open(path, 'rb') as f: content = f.read()