From 7ca89e41f1d154c0ce437df016f7671b9b4da75c Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 5 May 2020 14:45:31 +0100 Subject: [PATCH] parse json for status code, debug reason --- pydrive2/files.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pydrive2/files.py b/pydrive2/files.py index 97b9d934..14408f96 100644 --- a/pydrive2/files.py +++ b/pydrive2/files.py @@ -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) @@ -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)