Open mlucool opened 5 years ago
I see the error too in python 2.7 when uploading a binary file (uploading a text file seems okay). It seems like the problematic lines are https://github.com/jupyter-widgets/ipywidgets/blob/c592184935781d0787bf622bf1659279c4a8b531/ipywidgets/widgets/widget.py#L654
It's odd - I would have imagined that the lines above it that strip out the binary buffers would have taken care of the issue. Here's a theory: in python 2, strings are the same as binary buffers, so the binary buffers don't get stripped out. However, the json dumps function expects a utf-8 string. So when you transfer a binary buffer from the client to the kernel, it doesn't get stripped out in this check function, so we ask the json library to dump the state, which includes the binary buffer (aka string). That then causes the issue.
If that theory is right, we'd see the same issues with any client-side widget transferring a binary value to the kernel (e.g., images, etc.).
I'm not sure a good way around this. We'd need to distinguish between binary buffers and real strings, and that is exactly one of the major reasons for python 3.
It looks like our code is looking for these types in python 2 to strip out: https://github.com/jupyter-widgets/ipywidgets/blob/master/ipywidgets/widgets/widget.py#L59
I'm assuming the problematic thing here is the file's value. If so, why is the file's value not a bytearray or memoryview in python 2?
Anyway, hopefully that is some context for whoever wants to dig into this.
We do plan to release ipywidgets 8 before the end of the year, which will be python 3 only.
ipywidgets still supports 2.7, but the FileUpload widget does not work due to what looks like unicode vs. byte differences.
When I upload any file, I see:
Is it possible to fix this?