Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jupyter-gcs-contents-manager] Reading JSON files from GCS fails when running the contents manager under Python 3. #381

Open
ojarjur opened this issue Nov 21, 2020 · 0 comments

Comments

@ojarjur
Copy link
Collaborator

ojarjur commented Nov 21, 2020

Reproduction steps:

  1. Open a terminal in Jupyter(Lab)
  2. echo "{}" > test.json
  3. gsutil cp test.json gs://<BUCKET>/notebooks/jupyter

Try to open file in either Jupyter or JupyterLab

This looks like a bug in the way we handle files in GCS with a content type other than test/* when the contents manager is running in Python3.

As a work-around, you can specify a content type of text/plain when uploading the file to GCS, e.g.:

gsutil -h "Content-Type:text/plain" cp <FILE>.json gs://<BUCKET>/notebooks/jupyter/

Then the file will open in Jupyter and JupyterLab.

The root cause is this line

On that line we base64 encode the content before sticking it in an object that we later serialize to JSON. However, with Python3 that method returns a type of bytes instead of string, and Python JSON serialization does not support the type bytes.

The fix is to convert the response to a string before sticking it in the object. In short, we need to change that line to say

      blob_obj['content'] = base64.b64encode(content_str).decode(utf8_encoding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant