Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 6e1773a

Browse files
authored
Fix Pydatalab incompatibilities between Py2/3 (#367)
* Upgrading httplib2 to version 0.10.3. The 0.9.2 version does not work with Python 3. * Fix Pydatalab incompatibilities between Py2/3. These all have to do with bytes/string differences. * str() only takes one arg in py2. * Fix build breaks.
1 parent ec06b2c commit 6e1773a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

google/datalab/storage/commands/_storage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ def _gcs_view(args, _):
367367
contents = _get_object_contents(args['object'])
368368
if not isinstance(contents, basestring):
369369
contents = str(contents)
370-
lines = contents.split('\n')
370+
elif isinstance(contents, bytes):
371+
contents = str(contents, encoding='UTF-8')
372+
lines = contents.splitlines()
371373
head_count = args['head']
372374
tail_count = args['tail']
373375
if len(lines) > head_count + tail_count:

google/datalab/utils/_http.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def __init__(self, status, content):
4343
self.message = 'HTTP request failed'
4444
# Try extract a message from the body; swallow possible resulting ValueErrors and KeyErrors.
4545
try:
46-
error = json.loads(content)['error']
46+
if type(content) == str:
47+
error = json.loads(content)['error']
48+
else:
49+
error = json.loads(str(content, encoding='UTF-8'))['error']
4750
if 'errors' in error:
4851
error = error['errors'][0]
4952
self.message += ': ' + error['message']

0 commit comments

Comments
 (0)