JSON serialization / byte type error

Hi,
I have recently been converting bokeh apps over to python 3, which as we all know

has a distinction between bytes and strings. I have received an TypeError

“Object of type ‘bytes’ is not JSON serializable” for the first time. As it stands I have no

way to know what part of my code is at fault, since the message provides no

traceback. Is there a way to diagnose or correct this without inspecting every variable

one-by-one? Can I ask bokeh server to generate more thorough diagnostics? Is there

any other solution people aware of?

Thanks

JT

2018-09-10 21:14:53,168 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)

2018-09-10 21:14:53,171 Bokeh app running at: http://localhost:5006/multiplanet_vis

2018-09-10 21:14:53,171 Starting Bokeh server with process id: 22957

[0.20846054 0.48168106 0.42053804 … 0.50991985 0.3710494 0.1177326 ]

2018-09-10 21:14:54,329 200 GET /multiplanet_vis (::1) 665.28ms

2018-09-10 21:14:54,510 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=hC6lzkqEI26eyZ9IEFkz54n2DxwlSJrPRqqa8KA5jq6s (::1) 0.65ms

2018-09-10 21:14:54,510 WebSocket connection opened

2018-09-10 21:14:54,511 ServerConnection created

2018-09-10 21:14:54,539 error handling message Message ‘PULL-DOC-REQ’ (revision 1): TypeError(“Object of type ‘bytes’ is not JSON serializable”,)

Hi,

Set the --log-level to "debug"

Thanks,

Bryan

···

On Sep 10, 2018, at 18:26, Jason Tumlinson <[email protected]> wrote:

Hi,
   I have recently been converting bokeh apps over to python 3, which as we all know
has a distinction between bytes and strings. I have received an TypeError
“Object of type ‘bytes’ is not JSON serializable” for the first time. As it stands I have no
way to know what part of my code is at fault, since the message provides no
traceback. Is there a way to diagnose or correct this without inspecting every variable
one-by-one? Can I ask bokeh server to generate more thorough diagnostics? Is there
any other solution people aware of?

Thanks
JT

2018-09-10 21:14:53,168 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-09-10 21:14:53,171 Bokeh app running at: http://localhost:5006/multiplanet_vis
2018-09-10 21:14:53,171 Starting Bokeh server with process id: 22957
[0.20846054 0.48168106 0.42053804 ... 0.50991985 0.3710494 0.1177326 ]
2018-09-10 21:14:54,329 200 GET /multiplanet_vis (::1) 665.28ms
2018-09-10 21:14:54,510 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=hC6lzkqEI26eyZ9IEFkz54n2DxwlSJrPRqqa8KA5jq6s (::1) 0.65ms
2018-09-10 21:14:54,510 WebSocket connection opened
2018-09-10 21:14:54,511 ServerConnection created
2018-09-10 21:14:54,539 error handling message Message 'PULL-DOC-REQ' (revision 1): TypeError("Object of type 'bytes' is not JSON serializable",)

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/DE26AFC7-3DCB-49EC-85C1-8B85A02E1E38%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thanks Bryan for the super-quick response!

However, the longer traceback only lists code from bokeh and json, and does not, as far as I can tell,

indicate what part of my document is causing the error. Is there a way to do that?

Thanks

JT

townes:luvoir_simtools tumlinson$ bokeh serve --show multiplanet_vis --log-level debug

2018-09-10 21:37:29,406 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)

2018-09-10 21:37:29,407 These host origins can connect to the websocket: [‘localhost:5006’]

2018-09-10 21:37:29,408 Patterns are:

2018-09-10 21:37:29,408 [(’/multiplanet_vis/?’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.doc_handler.DocHandler’>,

2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,

2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),

2018-09-10 21:37:29,409 (’/multiplanet_vis/ws’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.ws.WSHandler’>,

2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,

2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),

2018-09-10 21:37:29,409 (’/multiplanet_vis/metadata’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.metadata_handler.MetadataHandler’>,

2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,

2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),

2018-09-10 21:37:29,409 (’/multiplanet_vis/autoload.js’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.autoload_js_handler.AutoloadJsHandler’>,

2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,

2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),

2018-09-10 21:37:29,409 (’/?’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.root_handler.RootHandler’>,

2018-09-10 21:37:29,409 {‘applications’: {’/multiplanet_vis’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>},

2018-09-10 21:37:29,409 ‘prefix’: ‘’,

2018-09-10 21:37:29,410 ‘use_redirect’: True}),

2018-09-10 21:37:29,410 (’/static/(.*)’,

2018-09-10 21:37:29,410 <class ‘bokeh.server.views.static_handler.StaticHandler’>)]

2018-09-10 21:37:29,411 Using selector: KqueueSelector

2018-09-10 21:37:29,412 Bokeh app running at: http://localhost:5006/multiplanet_vis

2018-09-10 21:37:29,412 Starting Bokeh server with process id: 23227

[0.20846054 0.48168106 0.42053804 … 0.50991985 0.3710494 0.1177326 ]

2018-09-10 21:37:30,221 200 GET /multiplanet_vis (::1) 677.21ms

2018-09-10 21:37:30,293 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w (::1) 0.76ms

2018-09-10 21:37:30,293 WebSocket connection opened

2018-09-10 21:37:30,293 Receiver created for Protocol(‘1.0’)

2018-09-10 21:37:30,294 ProtocolHandler created for Protocol(‘1.0’)

2018-09-10 21:37:30,294 ServerConnection created

2018-09-10 21:37:30,297 Sending pull-doc-reply from session ‘86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w’

2018-09-10 21:37:30,321 error handling message Message ‘PULL-DOC-REQ’ (revision 1): TypeError(“Object of type ‘bytes’ is not JSON serializable”,)

2018-09-10 21:37:30,321 message header {‘msgid’: ‘E86B8E2911F649939B01163EF4657C55’, ‘msgtype’: ‘PULL-DOC-REQ’} content {}

Traceback (most recent call last):

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/protocol_handler.py”, line 70, in handle

work = yield handler(message, connection)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py”, line 1099, in run

value = future.result()

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py”, line 1113, in run

yielded = self.gen.send(value)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py”, line 51, in _needs_document_lock_wrapper

result = yield yield_for_all_futures(func(self, *args, **kwargs))

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py”, line 194, in _handle_pull

return connection.protocol.create('PULL-DOC-REPLY', message.header['msgid'], self.document)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/init.py”, line 46, in create

return self._messages[msgtype].create(*args, **kwargs)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/messages/pull_doc_reply.py”, line 48, in create

content = { 'doc' : document.to_json() }

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py”, line 781, in to_json

doc_json = self.to_json_string()

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py”, line 810, in to_json_string

return serialize_json(json, indent=indent)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 213, in serialize_json

return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs)

File “/Users/tumlinson/anaconda3/lib/python3.6/json/init.py”, line 238, in dumps

**kw).encode(obj)

File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 199, in encode

chunks = self.iterencode(o, _one_shot=True)

File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 257, in iterencode

return _iterencode(o, 0)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 135, in default

return self.transform_python_types(obj)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 102, in transform_python_types

return super(BokehJSONEncoder, self).default(obj)

File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 180, in default

o.__class__.__name__)

TypeError: Object of type ‘bytes’ is not JSON serializable

···

On Sep 10, 2018, at 9:37 PM, Bryan Van de ven [email protected] wrote:

Hi,

Set the --log-level to “debug”

Thanks,

Bryan

On Sep 10, 2018, at 18:26, Jason Tumlinson [email protected] wrote:

Hi,
I have recently been converting bokeh apps over to python 3, which as we all know
has a distinction between bytes and strings. I have received an TypeError
“Object of type ‘bytes’ is not JSON serializable” for the first time. As it stands I have no
way to know what part of my code is at fault, since the message provides no
traceback. Is there a way to diagnose or correct this without inspecting every variable
one-by-one? Can I ask bokeh server to generate more thorough diagnostics? Is there
any other solution people aware of?

Thanks
JT

2018-09-10 21:14:53,168 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-09-10 21:14:53,171 Bokeh app running at: http://localhost:5006/multiplanet_vis
2018-09-10 21:14:53,171 Starting Bokeh server with process id: 22957
[0.20846054 0.48168106 0.42053804 … 0.50991985 0.3710494 0.1177326 ]
2018-09-10 21:14:54,329 200 GET /multiplanet_vis (::1) 665.28ms
2018-09-10 21:14:54,510 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=hC6lzkqEI26eyZ9IEFkz54n2DxwlSJrPRqqa8KA5jq6s (::1) 0.65ms
2018-09-10 21:14:54,510 WebSocket connection opened
2018-09-10 21:14:54,511 ServerConnection created
2018-09-10 21:14:54,539 error handling message Message ‘PULL-DOC-REQ’ (revision 1): TypeError(“Object of type ‘bytes’ is not JSON serializable”,)


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/DE26AFC7-3DCB-49EC-85C1-8B85A02E1E38%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/534A74AB-FF27-4F82-A186-A9808E5279EF%40anaconda.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hrm, perhaps unfortunately not. The entire document is passed to the Python stdlib JSON encoder, and the error is coming from inside the JSON encoder, which evidently does not provide any finer resolution than "I ha a problem". There's perhaps improvements that can be made somehow, but it will require investigation. As it happens someone else made an issue about essentially this same thing yesterday that you can follow:

  https://github.com/bokeh/bokeh/issues/8233

I would say the only hope is to catch problems with at the Bokeh property validation level somehow (since the JSON encoder is not informative, but we don't control it). It's possible your situation is already something that should result in a validation error, but fails to due to a bug. Without a minimum reproducible example it's hard to speculate more, however.

Thanks,

Bryan

···

On Sep 10, 2018, at 18:50, Jason Tumlinson <[email protected]> wrote:

Thanks Bryan for the super-quick response!

However, the longer traceback only lists code from bokeh and json, and does not, as far as I can tell,
indicate what part of my document is causing the error. Is there a way to do that?

Thanks
JT

townes:luvoir_simtools tumlinson$ bokeh serve --show multiplanet_vis --log-level debug
2018-09-10 21:37:29,406 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-09-10 21:37:29,407 These host origins can connect to the websocket: ['localhost:5006']
2018-09-10 21:37:29,408 Patterns are:
2018-09-10 21:37:29,408 [('/multiplanet_vis/?',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.doc_handler.DocHandler'>,
2018-09-10 21:37:29,409 {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 'bokeh_websocket_path': '/multiplanet_vis/ws'}),
2018-09-10 21:37:29,409 ('/multiplanet_vis/ws',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.ws.WSHandler'>,
2018-09-10 21:37:29,409 {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 'bokeh_websocket_path': '/multiplanet_vis/ws'}),
2018-09-10 21:37:29,409 ('/multiplanet_vis/metadata',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.metadata_handler.MetadataHandler'>,
2018-09-10 21:37:29,409 {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 'bokeh_websocket_path': '/multiplanet_vis/ws'}),
2018-09-10 21:37:29,409 ('/multiplanet_vis/autoload.js',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.autoload_js_handler.AutoloadJsHandler'>,
2018-09-10 21:37:29,409 {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 'bokeh_websocket_path': '/multiplanet_vis/ws'}),
2018-09-10 21:37:29,409 ('/?',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.root_handler.RootHandler'>,
2018-09-10 21:37:29,409 {'applications': {'/multiplanet_vis': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>},
2018-09-10 21:37:29,409 'prefix': '',
2018-09-10 21:37:29,410 'use_redirect': True}),
2018-09-10 21:37:29,410 ('/static/(.*)',
2018-09-10 21:37:29,410 <class 'bokeh.server.views.static_handler.StaticHandler'>)]
2018-09-10 21:37:29,411 Using selector: KqueueSelector
2018-09-10 21:37:29,412 Bokeh app running at: http://localhost:5006/multiplanet_vis
2018-09-10 21:37:29,412 Starting Bokeh server with process id: 23227
[0.20846054 0.48168106 0.42053804 ... 0.50991985 0.3710494 0.1177326 ]
2018-09-10 21:37:30,221 200 GET /multiplanet_vis (::1) 677.21ms
2018-09-10 21:37:30,293 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w (::1) 0.76ms
2018-09-10 21:37:30,293 WebSocket connection opened
2018-09-10 21:37:30,293 Receiver created for Protocol('1.0')
2018-09-10 21:37:30,294 ProtocolHandler created for Protocol('1.0')
2018-09-10 21:37:30,294 ServerConnection created
2018-09-10 21:37:30,297 Sending pull-doc-reply from session '86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w'
2018-09-10 21:37:30,321 error handling message Message 'PULL-DOC-REQ' (revision 1): TypeError("Object of type 'bytes' is not JSON serializable",)
2018-09-10 21:37:30,321 message header {'msgid': 'E86B8E2911F649939B01163EF4657C55', 'msgtype': 'PULL-DOC-REQ'} content {}
Traceback (most recent call last):
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/protocol_handler.py", line 70, in handle
    work = yield handler(message, connection)
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
    value = future.result()
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1113, in run
    yielded = self.gen.send(value)
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py", line 51, in _needs_document_lock_wrapper
    result = yield yield_for_all_futures(func(self, *args, **kwargs))
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py", line 194, in _handle_pull
    return connection.protocol.create('PULL-DOC-REPLY', message.header['msgid'], self.document)
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/__init__.py", line 46, in create
    return self._messages[msgtype].create(*args, **kwargs)
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/messages/pull_doc_reply.py", line 48, in create
    content = { 'doc' : document.to_json() }
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py", line 781, in to_json
    doc_json = self.to_json_string()
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py", line 810, in to_json_string
    return serialize_json(json, indent=indent)
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 213, in serialize_json
    return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs)
  File "/Users/tumlinson/anaconda3/lib/python3.6/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 135, in default
    return self.transform_python_types(obj)
  File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 102, in transform_python_types
    return super(BokehJSONEncoder, self).default(obj)
  File "/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'bytes' is not JSON serializable

On Sep 10, 2018, at 9:37 PM, Bryan Van de ven <[email protected]> wrote:

Hi,

Set the --log-level to "debug"

Thanks,

Bryan

On Sep 10, 2018, at 18:26, Jason Tumlinson <[email protected]> wrote:

Hi,
  I have recently been converting bokeh apps over to python 3, which as we all know
has a distinction between bytes and strings. I have received an TypeError
“Object of type ‘bytes’ is not JSON serializable” for the first time. As it stands I have no
way to know what part of my code is at fault, since the message provides no
traceback. Is there a way to diagnose or correct this without inspecting every variable
one-by-one? Can I ask bokeh server to generate more thorough diagnostics? Is there
any other solution people aware of?

Thanks
JT

2018-09-10 21:14:53,168 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-09-10 21:14:53,171 Bokeh app running at: http://localhost:5006/multiplanet_vis
2018-09-10 21:14:53,171 Starting Bokeh server with process id: 22957
[0.20846054 0.48168106 0.42053804 ... 0.50991985 0.3710494 0.1177326 ]
2018-09-10 21:14:54,329 200 GET /multiplanet_vis (::1) 665.28ms
2018-09-10 21:14:54,510 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=hC6lzkqEI26eyZ9IEFkz54n2DxwlSJrPRqqa8KA5jq6s (::1) 0.65ms
2018-09-10 21:14:54,510 WebSocket connection opened
2018-09-10 21:14:54,511 ServerConnection created
2018-09-10 21:14:54,539 error handling message Message 'PULL-DOC-REQ' (revision 1): TypeError("Object of type 'bytes' is not JSON serializable",)

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/DE26AFC7-3DCB-49EC-85C1-8B85A02E1E38%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/534A74AB-FF27-4F82-A186-A9808E5279EF%40anaconda.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A86454C8-EEC6-4CD1-974C-67C7998A883E%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Jason and Bryan,

(I’m new to the group, so my apologies if I’m missing some of the context re: bokeh.) Perhaps you could write a test that utilizes the unittest.mock library to replace the call to JSONEncoder in the JSON library (presuming this is the point it trips up?) to give you more information.

Essentially, you’d write something like:

class TestClass(unittest.TestCase):

def extend_json_encoder(self, input):
    print(input)
    try:
        output = json.JSONENcoder(input)
        print(output)
        return(output)
    except:
        print("Error at JSONEncoder")

def test_bokeh_app(self):
    with unittest.mock.patch('json.JSONEncoder', new=self.extend_json_encoder()):
        # call your methods

``

Thanks,
Zoë

···

On Tuesday, September 11, 2018 at 11:48:00 AM UTC-4, Bryan Van de ven wrote:

Hrm, perhaps unfortunately not. The entire document is passed to the Python stdlib JSON encoder, and the error is coming from inside the JSON encoder, which evidently does not provide any finer resolution than “I ha a problem”. There’s perhaps improvements that can be made somehow, but it will require investigation. As it happens someone else made an issue about essentially this same thing yesterday that you can follow:

    [https://github.com/bokeh/bokeh/issues/8233](https://github.com/bokeh/bokeh/issues/8233)

I would say the only hope is to catch problems with at the Bokeh property validation level somehow (since the JSON encoder is not informative, but we don’t control it). It’s possible your situation is already something that should result in a validation error, but fails to due to a bug. Without a minimum reproducible example it’s hard to speculate more, however.

Thanks,

Bryan

On Sep 10, 2018, at 18:50, Jason Tumlinson [email protected] wrote:

Thanks Bryan for the super-quick response!

However, the longer traceback only lists code from bokeh and json, and does not, as far as I can tell,
indicate what part of my document is causing the error. Is there a way to do that?

Thanks

JT

townes:luvoir_simtools tumlinson$ bokeh serve --show multiplanet_vis --log-level debug
2018-09-10 21:37:29,406 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)

2018-09-10 21:37:29,407 These host origins can connect to the websocket: [‘localhost:5006’]

2018-09-10 21:37:29,408 Patterns are:

2018-09-10 21:37:29,408 [(’/multiplanet_vis/?’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.doc_handler.DocHandler’>,

2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,

2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),

2018-09-10 21:37:29,409 (’/multiplanet_vis/ws’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.ws.WSHandler’>,

2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,

2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),

2018-09-10 21:37:29,409 (’/multiplanet_vis/metadata’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.metadata_handler.MetadataHandler’>,

2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,

2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),

2018-09-10 21:37:29,409 (’/multiplanet_vis/autoload.js’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.autoload_js_handler.AutoloadJsHandler’>,

2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,

2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),

2018-09-10 21:37:29,409 (’/?’,

2018-09-10 21:37:29,409 <class ‘bokeh.server.views.root_handler.RootHandler’>,

2018-09-10 21:37:29,409 {‘applications’: {’/multiplanet_vis’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>},

2018-09-10 21:37:29,409 ‘prefix’: ‘’,

2018-09-10 21:37:29,410 ‘use_redirect’: True}),

2018-09-10 21:37:29,410 (’/static/(.*)’,

2018-09-10 21:37:29,410 <class ‘bokeh.server.views.static_handler.StaticHandler’>)]

2018-09-10 21:37:29,411 Using selector: KqueueSelector

2018-09-10 21:37:29,412 Bokeh app running at: http://localhost:5006/multiplanet_vis

2018-09-10 21:37:29,412 Starting Bokeh server with process id: 23227

[0.20846054 0.48168106 0.42053804 … 0.50991985 0.3710494 0.1177326 ]

2018-09-10 21:37:30,221 200 GET /multiplanet_vis (::1) 677.21ms

2018-09-10 21:37:30,293 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w (::1) 0.76ms

2018-09-10 21:37:30,293 WebSocket connection opened

2018-09-10 21:37:30,293 Receiver created for Protocol(‘1.0’)

2018-09-10 21:37:30,294 ProtocolHandler created for Protocol(‘1.0’)

2018-09-10 21:37:30,294 ServerConnection created

2018-09-10 21:37:30,297 Sending pull-doc-reply from session ‘86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w’

2018-09-10 21:37:30,321 error handling message Message ‘PULL-DOC-REQ’ (revision 1): TypeError(“Object of type ‘bytes’ is not JSON serializable”,)

2018-09-10 21:37:30,321 message header {‘msgid’: ‘E86B8E2911F649939B01163EF4657C55’, ‘msgtype’: ‘PULL-DOC-REQ’} content {}

Traceback (most recent call last):

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/protocol_handler.py”, line 70, in handle

work = yield handler(message, connection)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py”, line 1099, in run

value = future.result()

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py”, line 1113, in run

yielded = self.gen.send(value)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py”, line 51, in _needs_document_lock_wrapper

result = yield yield_for_all_futures(func(self, *args, **kwargs))

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py”, line 194, in _handle_pull

return connection.protocol.create('PULL-DOC-REPLY', message.header['msgid'], self.document)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/init.py”, line 46, in create

return self._messages[msgtype].create(*args, **kwargs)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/messages/pull_doc_reply.py”, line 48, in create

content = { 'doc' : document.to_json() }

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py”, line 781, in to_json

doc_json = self.to_json_string()

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py”, line 810, in to_json_string

return serialize_json(json, indent=indent)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 213, in serialize_json

return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs)

File “/Users/tumlinson/anaconda3/lib/python3.6/json/init.py”, line 238, in dumps

**kw).encode(obj)

File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 199, in encode

chunks = self.iterencode(o, _one_shot=True)

File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 257, in iterencode

return _iterencode(o, 0)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 135, in default

return self.transform_python_types(obj)

File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 102, in transform_python_types

return super(BokehJSONEncoder, self).default(obj)

File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 180, in default

o.__class__.__name__)

TypeError: Object of type ‘bytes’ is not JSON serializable

On Sep 10, 2018, at 9:37 PM, Bryan Van de ven [email protected] wrote:

Hi,

Set the --log-level to “debug”

Thanks,

Bryan

On Sep 10, 2018, at 18:26, Jason Tumlinson [email protected] wrote:

Hi,

    I have recently been converting bokeh apps over to python 3, which as we all know

has a distinction between bytes and strings. I have received an TypeError

“Object of type ‘bytes’ is not JSON serializable” for the first time. As it stands I have no
way to know what part of my code is at fault, since the message provides no
traceback. Is there a way to diagnose or correct this without inspecting every variable
one-by-one? Can I ask bokeh server to generate more thorough diagnostics? Is there
any other solution people aware of?

Thanks

JT

2018-09-10 21:14:53,168 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)

2018-09-10 21:14:53,171 Bokeh app running at: http://localhost:5006/multiplanet_vis

2018-09-10 21:14:53,171 Starting Bokeh server with process id: 22957

[0.20846054 0.48168106 0.42053804 … 0.50991985 0.3710494 0.1177326 ]

2018-09-10 21:14:54,329 200 GET /multiplanet_vis (::1) 665.28ms

2018-09-10 21:14:54,510 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=hC6lzkqEI26eyZ9IEFkz54n2DxwlSJrPRqqa8KA5jq6s (::1) 0.65ms

2018-09-10 21:14:54,510 WebSocket connection opened

2018-09-10 21:14:54,511 ServerConnection created

2018-09-10 21:14:54,539 error handling message Message ‘PULL-DOC-REQ’ (revision 1): TypeError(“Object of type ‘bytes’ is not JSON serializable”,)


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/DE26AFC7-3DCB-49EC-85C1-8B85A02E1E38%40gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/534A74AB-FF27-4F82-A186-A9808E5279EF%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A86454C8-EEC6-4CD1-974C-67C7998A883E%40gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi
Just following up on this since I have done more investigation. The first sign of the problem is the error

"TypeError: Object of type ‘bytes’ is not JSON serializable”. The bokeh traceback (see below) pointed

me toward bokeh/core/json_encoder.py, where the transform_python_types method on class BokehJSONEncoder

exists to catch particular types that will trip up the JSON serializer (like pandas stuff). It does not catch byte types,

it just passes them on. Unfortunately I have bytes all over my code since it was originally developed in

python 2.7. Rather than chase down all the places this happens in the original code, I tried adding

a test to catch this in bokeh/core/json_encoder.py like so:

added here by JT 092318

try:

return obj.decode()

except AttributeError:

pass

This fix by itself got all my code to run just fine with no apparent issues.

So I thought I better report this. I don’t know if it’s a fix that should be done in bokeh or whether it would be considered

better practice to fix all the original creation of byte objects. I suspect, but haven’t yet proven, that these bytes are

only a problem if they are included in bokeh DataSource or ColumnDataSource objects, not just in plot

labels, etc.

Is this worth creating an issue for?

Thanks

JT

···

On Sep 11, 2018, at 11:47 AM, Bryan Van de ven [email protected] wrote:

Hrm, perhaps unfortunately not. The entire document is passed to the Python stdlib JSON encoder, and the error is coming from inside the JSON encoder, which evidently does not provide any finer resolution than “I ha a problem”. There’s perhaps improvements that can be made somehow, but it will require investigation. As it happens someone else made an issue about essentially this same thing yesterday that you can follow:

https://github.com/bokeh/bokeh/issues/8233

I would say the only hope is to catch problems with at the Bokeh property validation level somehow (since the JSON encoder is not informative, but we don’t control it). It’s possible your situation is already something that should result in a validation error, but fails to due to a bug. Without a minimum reproducible example it’s hard to speculate more, however.

Thanks,

Bryan

On Sep 10, 2018, at 18:50, Jason Tumlinson [email protected] wrote:

Thanks Bryan for the super-quick response!

However, the longer traceback only lists code from bokeh and json, and does not, as far as I can tell,
indicate what part of my document is causing the error. Is there a way to do that?

Thanks
JT

townes:luvoir_simtools tumlinson$ bokeh serve --show multiplanet_vis --log-level debug
2018-09-10 21:37:29,406 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-09-10 21:37:29,407 These host origins can connect to the websocket: [‘localhost:5006’]
2018-09-10 21:37:29,408 Patterns are:
2018-09-10 21:37:29,408 [(’/multiplanet_vis/?’,
2018-09-10 21:37:29,409 <class ‘bokeh.server.views.doc_handler.DocHandler’>,
2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),
2018-09-10 21:37:29,409 (’/multiplanet_vis/ws’,
2018-09-10 21:37:29,409 <class ‘bokeh.server.views.ws.WSHandler’>,
2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),
2018-09-10 21:37:29,409 (’/multiplanet_vis/metadata’,
2018-09-10 21:37:29,409 <class ‘bokeh.server.views.metadata_handler.MetadataHandler’>,
2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),
2018-09-10 21:37:29,409 (’/multiplanet_vis/autoload.js’,
2018-09-10 21:37:29,409 <class ‘bokeh.server.views.autoload_js_handler.AutoloadJsHandler’>,
2018-09-10 21:37:29,409 {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 ‘bokeh_websocket_path’: ‘/multiplanet_vis/ws’}),
2018-09-10 21:37:29,409 (’/?’,
2018-09-10 21:37:29,409 <class ‘bokeh.server.views.root_handler.RootHandler’>,
2018-09-10 21:37:29,409 {‘applications’: {’/multiplanet_vis’: <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>},
2018-09-10 21:37:29,409 ‘prefix’: ‘’,
2018-09-10 21:37:29,410 ‘use_redirect’: True}),
2018-09-10 21:37:29,410 (’/static/(.*)’,
2018-09-10 21:37:29,410 <class ‘bokeh.server.views.static_handler.StaticHandler’>)]
2018-09-10 21:37:29,411 Using selector: KqueueSelector
2018-09-10 21:37:29,412 Bokeh app running at: http://localhost:5006/multiplanet_vis
2018-09-10 21:37:29,412 Starting Bokeh server with process id: 23227
[0.20846054 0.48168106 0.42053804 … 0.50991985 0.3710494 0.1177326 ]
2018-09-10 21:37:30,221 200 GET /multiplanet_vis (::1) 677.21ms
2018-09-10 21:37:30,293 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w (::1) 0.76ms
2018-09-10 21:37:30,293 WebSocket connection opened
2018-09-10 21:37:30,293 Receiver created for Protocol(‘1.0’)
2018-09-10 21:37:30,294 ProtocolHandler created for Protocol(‘1.0’)
2018-09-10 21:37:30,294 ServerConnection created
2018-09-10 21:37:30,297 Sending pull-doc-reply from session ‘86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w’
2018-09-10 21:37:30,321 error handling message Message ‘PULL-DOC-REQ’ (revision 1): TypeError(“Object of type ‘bytes’ is not JSON serializable”,)
2018-09-10 21:37:30,321 message header {‘msgid’: ‘E86B8E2911F649939B01163EF4657C55’, ‘msgtype’: ‘PULL-DOC-REQ’} content {}
Traceback (most recent call last):
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/protocol_handler.py”, line 70, in handle
work = yield handler(message, connection)
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py”, line 1099, in run
value = future.result()
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py”, line 1113, in run
yielded = self.gen.send(value)
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py”, line 51, in _needs_document_lock_wrapper
result = yield yield_for_all_futures(func(self, *args, **kwargs))
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py”, line 194, in _handle_pull
return connection.protocol.create(‘PULL-DOC-REPLY’, message.header[‘msgid’], self.document)
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/init.py”, line 46, in create
return self._messages[msgtype].create(*args, **kwargs)
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/messages/pull_doc_reply.py”, line 48, in create
content = { ‘doc’ : document.to_json() }
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py”, line 781, in to_json
doc_json = self.to_json_string()
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py”, line 810, in to_json_string
return serialize_json(json, indent=indent)
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 213, in serialize_json
return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs)
File “/Users/tumlinson/anaconda3/lib/python3.6/json/init.py”, line 238, in dumps
**kw).encode(obj)
File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 257, in iterencode
return _iterencode(o, 0)
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 135, in default
return self.transform_python_types(obj)
File “/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py”, line 102, in transform_python_types
return super(BokehJSONEncoder, self).default(obj)
File “/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py”, line 180, in default
o.class.name)
TypeError: Object of type ‘bytes’ is not JSON serializable

On Sep 10, 2018, at 9:37 PM, Bryan Van de ven [email protected] wrote:

Hi,

Set the --log-level to “debug”

Thanks,

Bryan

On Sep 10, 2018, at 18:26, Jason Tumlinson [email protected] wrote:

Hi,
I have recently been converting bokeh apps over to python 3, which as we all know
has a distinction between bytes and strings. I have received an TypeError
“Object of type ‘bytes’ is not JSON serializable” for the first time. As it stands I have no
way to know what part of my code is at fault, since the message provides no
traceback. Is there a way to diagnose or correct this without inspecting every variable
one-by-one? Can I ask bokeh server to generate more thorough diagnostics? Is there
any other solution people aware of?

Thanks
JT

2018-09-10 21:14:53,168 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-09-10 21:14:53,171 Bokeh app running at: http://localhost:5006/multiplanet_vis
2018-09-10 21:14:53,171 Starting Bokeh server with process id: 22957
[0.20846054 0.48168106 0.42053804 … 0.50991985 0.3710494 0.1177326 ]
2018-09-10 21:14:54,329 200 GET /multiplanet_vis (::1) 665.28ms
2018-09-10 21:14:54,510 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=hC6lzkqEI26eyZ9IEFkz54n2DxwlSJrPRqqa8KA5jq6s (::1) 0.65ms
2018-09-10 21:14:54,510 WebSocket connection opened
2018-09-10 21:14:54,511 ServerConnection created
2018-09-10 21:14:54,539 error handling message Message ‘PULL-DOC-REQ’ (revision 1): TypeError(“Object of type ‘bytes’ is not JSON serializable”,)


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/DE26AFC7-3DCB-49EC-85C1-8B85A02E1E38%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/534A74AB-FF27-4F82-A186-A9808E5279EF%40anaconda.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A86454C8-EEC6-4CD1-974C-67C7998A883E%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/84645522-B399-4FDC-B862-7C3395A82758%40anaconda.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

Yes certainly an issue with as much detail as possible is appropriate for this.

Thanks,

Bryan

···

On Sep 11, 2018, at 11:47, Bryan Van de ven <[email protected]> wrote:

Hrm, perhaps unfortunately not. The entire document is passed to the Python stdlib JSON encoder, and the error is coming from inside the JSON encoder, which evidently does not provide any finer resolution than "I ha a problem". There's perhaps improvements that can be made somehow, but it will require investigation. As it happens someone else made an issue about essentially this same thing yesterday that you can follow:

  https://github.com/bokeh/bokeh/issues/8233

I would say the only hope is to catch problems with at the Bokeh property validation level somehow (since the JSON encoder is not informative, but we don't control it). It's possible your situation is already something that should result in a validation error, but fails to due to a bug. Without a minimum reproducible example it's hard to speculate more, however.

Thanks,

Bryan

On Sep 10, 2018, at 18:50, Jason Tumlinson <[email protected]> wrote:

Thanks Bryan for the super-quick response!

However, the longer traceback only lists code from bokeh and json, and does not, as far as I can tell,
indicate what part of my document is causing the error. Is there a way to do that?

Thanks
JT

townes:luvoir_simtools tumlinson$ bokeh serve --show multiplanet_vis --log-level debug
2018-09-10 21:37:29,406 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-09-10 21:37:29,407 These host origins can connect to the websocket: ['localhost:5006']
2018-09-10 21:37:29,408 Patterns are:
2018-09-10 21:37:29,408 [('/multiplanet_vis/?',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.doc_handler.DocHandler'>,
2018-09-10 21:37:29,409 {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 'bokeh_websocket_path': '/multiplanet_vis/ws'}),
2018-09-10 21:37:29,409 ('/multiplanet_vis/ws',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.ws.WSHandler'>,
2018-09-10 21:37:29,409 {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 'bokeh_websocket_path': '/multiplanet_vis/ws'}),
2018-09-10 21:37:29,409 ('/multiplanet_vis/metadata',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.metadata_handler.MetadataHandler'>,
2018-09-10 21:37:29,409 {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 'bokeh_websocket_path': '/multiplanet_vis/ws'}),
2018-09-10 21:37:29,409 ('/multiplanet_vis/autoload.js',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.autoload_js_handler.AutoloadJsHandler'>,
2018-09-10 21:37:29,409 {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>,
2018-09-10 21:37:29,409 'bokeh_websocket_path': '/multiplanet_vis/ws'}),
2018-09-10 21:37:29,409 ('/?',
2018-09-10 21:37:29,409 <class 'bokeh.server.views.root_handler.RootHandler'>,
2018-09-10 21:37:29,409 {'applications': {'/multiplanet_vis': <bokeh.server.application_context.ApplicationContext object at 0x10a7ca630>},
2018-09-10 21:37:29,409 'prefix': '',
2018-09-10 21:37:29,410 'use_redirect': True}),
2018-09-10 21:37:29,410 ('/static/(.*)',
2018-09-10 21:37:29,410 <class 'bokeh.server.views.static_handler.StaticHandler'>)]
2018-09-10 21:37:29,411 Using selector: KqueueSelector
2018-09-10 21:37:29,412 Bokeh app running at: http://localhost:5006/multiplanet_vis
2018-09-10 21:37:29,412 Starting Bokeh server with process id: 23227
[0.20846054 0.48168106 0.42053804 ... 0.50991985 0.3710494 0.1177326 ]
2018-09-10 21:37:30,221 200 GET /multiplanet_vis (::1) 677.21ms
2018-09-10 21:37:30,293 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w (::1) 0.76ms
2018-09-10 21:37:30,293 WebSocket connection opened
2018-09-10 21:37:30,293 Receiver created for Protocol('1.0')
2018-09-10 21:37:30,294 ProtocolHandler created for Protocol('1.0')
2018-09-10 21:37:30,294 ServerConnection created
2018-09-10 21:37:30,297 Sending pull-doc-reply from session '86EAjD4uMSlykkdptSpoE8JVwdv7lyJHTFFgcDhOWP1w'
2018-09-10 21:37:30,321 error handling message Message 'PULL-DOC-REQ' (revision 1): TypeError("Object of type 'bytes' is not JSON serializable",)
2018-09-10 21:37:30,321 message header {'msgid': 'E86B8E2911F649939B01163EF4657C55', 'msgtype': 'PULL-DOC-REQ'} content {}
Traceback (most recent call last):
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/protocol_handler.py", line 70, in handle
   work = yield handler(message, connection)
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
   value = future.result()
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1113, in run
   yielded = self.gen.send(value)
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py", line 51, in _needs_document_lock_wrapper
   result = yield yield_for_all_futures(func(self, *args, **kwargs))
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/server/session.py", line 194, in _handle_pull
   return connection.protocol.create('PULL-DOC-REPLY', message.header['msgid'], self.document)
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/__init__.py", line 46, in create
   return self._messages[msgtype].create(*args, **kwargs)
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/protocol/messages/pull_doc_reply.py", line 48, in create
   content = { 'doc' : document.to_json() }
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py", line 781, in to_json
   doc_json = self.to_json_string()
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/document/document.py", line 810, in to_json_string
   return serialize_json(json, indent=indent)
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 213, in serialize_json
   return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs)
File "/Users/tumlinson/anaconda3/lib/python3.6/json/__init__.py", line 238, in dumps
   **kw).encode(obj)
File "/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py", line 199, in encode
   chunks = self.iterencode(o, _one_shot=True)
File "/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py", line 257, in iterencode
   return _iterencode(o, 0)
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 135, in default
   return self.transform_python_types(obj)
File "/Users/tumlinson/anaconda3/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 102, in transform_python_types
   return super(BokehJSONEncoder, self).default(obj)
File "/Users/tumlinson/anaconda3/lib/python3.6/json/encoder.py", line 180, in default
   o.__class__.__name__)
TypeError: Object of type 'bytes' is not JSON serializable

On Sep 10, 2018, at 9:37 PM, Bryan Van de ven <[email protected]> wrote:

Hi,

Set the --log-level to "debug"

Thanks,

Bryan

On Sep 10, 2018, at 18:26, Jason Tumlinson <[email protected]> wrote:

Hi,
  I have recently been converting bokeh apps over to python 3, which as we all know
has a distinction between bytes and strings. I have received an TypeError
“Object of type ‘bytes’ is not JSON serializable” for the first time. As it stands I have no
way to know what part of my code is at fault, since the message provides no
traceback. Is there a way to diagnose or correct this without inspecting every variable
one-by-one? Can I ask bokeh server to generate more thorough diagnostics? Is there
any other solution people aware of?

Thanks
JT

2018-09-10 21:14:53,168 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-09-10 21:14:53,171 Bokeh app running at: http://localhost:5006/multiplanet_vis
2018-09-10 21:14:53,171 Starting Bokeh server with process id: 22957
[0.20846054 0.48168106 0.42053804 ... 0.50991985 0.3710494 0.1177326 ]
2018-09-10 21:14:54,329 200 GET /multiplanet_vis (::1) 665.28ms
2018-09-10 21:14:54,510 101 GET /multiplanet_vis/ws?bokeh-protocol-version=1.0&bokeh-session-id=hC6lzkqEI26eyZ9IEFkz54n2DxwlSJrPRqqa8KA5jq6s (::1) 0.65ms
2018-09-10 21:14:54,510 WebSocket connection opened
2018-09-10 21:14:54,511 ServerConnection created
2018-09-10 21:14:54,539 error handling message Message 'PULL-DOC-REQ' (revision 1): TypeError("Object of type 'bytes' is not JSON serializable",)

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/DE26AFC7-3DCB-49EC-85C1-8B85A02E1E38%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/534A74AB-FF27-4F82-A186-A9808E5279EF%40anaconda.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A86454C8-EEC6-4CD1-974C-67C7998A883E%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.