diff --git a/IPython/html/base/zmqhandlers.py b/IPython/html/base/zmqhandlers.py index eedf71e..5ddb5d2 100644 --- a/IPython/html/base/zmqhandlers.py +++ b/IPython/html/base/zmqhandlers.py @@ -8,6 +8,7 @@ import os import json import struct import warnings +import sys try: from urllib.parse import urlparse # Py 3 @@ -43,8 +44,8 @@ def serialize_binary_message(msg): # don't modify msg or buffer list in-place msg = msg.copy() buffers = list(msg.pop('buffers')) - # for python 2, copy the buffer memoryviews to byte strings - buffers = [x.tobytes() for x in buffers] + if sys.version_info < (3, 4): + buffers = [x.tobytes() for x in buffers] bmsg = json.dumps(msg, default=date_default).encode('utf8') buffers.insert(0, bmsg) nbufs = len(buffers)