diff --git a/google/datalab/storage/commands/_storage.py b/google/datalab/storage/commands/_storage.py index 9d5327214..32043a294 100644 --- a/google/datalab/storage/commands/_storage.py +++ b/google/datalab/storage/commands/_storage.py @@ -367,7 +367,9 @@ def _gcs_view(args, _): contents = _get_object_contents(args['object']) if not isinstance(contents, basestring): contents = str(contents) - lines = contents.split('\n') + elif isinstance(contents, bytes): + contents = str(contents, encoding='UTF-8') + lines = contents.splitlines() head_count = args['head'] tail_count = args['tail'] if len(lines) > head_count + tail_count: diff --git a/google/datalab/utils/_http.py b/google/datalab/utils/_http.py index 0254c96fc..c41a32ac0 100644 --- a/google/datalab/utils/_http.py +++ b/google/datalab/utils/_http.py @@ -43,7 +43,10 @@ def __init__(self, status, content): self.message = 'HTTP request failed' # Try extract a message from the body; swallow possible resulting ValueErrors and KeyErrors. try: - error = json.loads(content)['error'] + if type(content) == str: + error = json.loads(content)['error'] + else: + error = json.loads(str(content, encoding='UTF-8'))['error'] if 'errors' in error: error = error['errors'][0] self.message += ': ' + error['message']