Skip to content

Commit

Permalink
parse json for status code, debug reason
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed May 5, 2020
1 parent e57aca7 commit 7ca89e4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pydrive2/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def __init__(self, http_error):
assert isinstance(http_error, errors.HttpError)
content = json.loads(http_error.content.decode("utf-8"))
self.error = content.get("error", {}) if content else {}
self.status = http_error.resp.status

# Initialize args for backward compatibility
super().__init__(http_error)
Expand Down Expand Up @@ -255,14 +254,17 @@ def download(fd, request):
try:
download(fd, files.get_media(fileId=file_id))
except errors.HttpError as error:
err = ApiRequestError(error)
if err.status != 403 or "use export" not in err.error["message"]:
raise
exc = ApiRequestError(error)
reason = exc.error.get("errors", [{}])[0].get("reason", "")
if exc.error["code"] != 403 or reason != "??":
print(reason)
raise exc
mimetype = mimetype or "text/plain"
fd.seek(0)
fd.seek(0) # just in case `download()` modified `fd`
try:
download(
fd, files.export_media(fileId=file_id, mimeType=mimetype)
fd,
files.export_media(fileId=file_id, mimeType=mimetype),
)
except errors.HttpError as error:
raise ApiRequestError(error)
Expand Down

0 comments on commit 7ca89e4

Please sign in to comment.