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

utils._http: Fix bytes -> str for py3 #340

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions datalab/utils/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,12 @@ def request(url, args=None, data=None, headers=None, method=None,
method=method,
body=data,
headers=headers)
content = content.decode()
if 200 <= response.status < 300:
if raw_response:
return content
if type(content) == str:
return json.loads(content)
else:
return json.loads(str(content, encoding='UTF-8'))
return json.loads(content)
else:
raise RequestException(response.status, content)
except ValueError:
Expand Down
5 changes: 2 additions & 3 deletions google/datalab/utils/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,12 @@ def request(url, args=None, data=None, headers=None, method=None,
method=method,
body=data,
headers=headers)
content = content.decode()
if 200 <= response.status < 300:
if raw_response:
return content
if type(content) == str:
return json.loads(content)
else:
return json.loads(str(content, encoding='UTF-8'))
return json.loads(content)
else:
raise RequestException(response.status, content)
except ValueError:
Expand Down