From 5639ac71342baa850ff601c72a93094650d3984a Mon Sep 17 00:00:00 2001 From: Michael Marchetti Date: Thu, 3 Dec 2015 08:38:50 -0500 Subject: [PATCH 1/2] Fix secondary error that occurs during handling of HTTP 500 status In log.py, we're attempting to log the request headers when a 500-series error occurs, but tornado.httputil.HTTPHeaders isn't a dict - it inherits from collections.MutableMapping. So it fails during JSON serialization. The fix is to convert it to a dict first. Unfortunately, the HTTPHeaders class doesn't expose any methods to access the underlying dictionary (`request.headers._dict`) directly, so we recreate it using the public API. --- notebook/log.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notebook/log.py b/notebook/log.py index eecd39a00..9e727f0b7 100644 --- a/notebook/log.py +++ b/notebook/log.py @@ -43,6 +43,7 @@ def log_request(handler): msg = msg + ' referer={referer}' if status >= 500 and status != 502: # log all headers if it caused an error - log_method(json.dumps(request.headers, indent=2)) + headers = { k: request.headers[k] for k in request.headers } + log_method(json.dumps(headers, indent=2)) log_method(msg.format(**ns)) From 536a6d64dc2a80347d5917ce955ff8cd9eab59be Mon Sep 17 00:00:00 2001 From: Michael Marchetti Date: Thu, 3 Dec 2015 12:49:12 -0500 Subject: [PATCH 2/2] Use `dict()` to convert the mapping to a dictionary --- notebook/log.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/notebook/log.py b/notebook/log.py index 9e727f0b7..dab330cb4 100644 --- a/notebook/log.py +++ b/notebook/log.py @@ -43,7 +43,6 @@ def log_request(handler): msg = msg + ' referer={referer}' if status >= 500 and status != 502: # log all headers if it caused an error - headers = { k: request.headers[k] for k in request.headers } - log_method(json.dumps(headers, indent=2)) + log_method(json.dumps(dict(request.headers), indent=2)) log_method(msg.format(**ns))