From 0dc5fe4ff3506b1bcb235cf4cf458f4e32047657 Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Tue, 24 Mar 2020 17:20:41 +0000 Subject: [PATCH] Retrieve access denied error message --- gdown/download.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gdown/download.py b/gdown/download.py index 19a38c4b..b1f0ca0f 100644 --- a/gdown/download.py +++ b/gdown/download.py @@ -38,6 +38,10 @@ def get_url_from_gdrive_confirmation(contents): url = url.replace("\\u003d", "=") url = url.replace("\\u0026", "&") return url + m = re.search('

(.*)

', line) + if m: + error = m.groups()[0] + raise RuntimeError(error) def download(url, output=None, quiet=False, proxy=None, speed=None): @@ -86,7 +90,21 @@ def download(url, output=None, quiet=False, proxy=None, speed=None): break # Need to redirect with confirmation - url = get_url_from_gdrive_confirmation(res.text) + try: + url = get_url_from_gdrive_confirmation(res.text) + except RuntimeError as e: + print("Access denied with the following error:") + import textwrap + + error = "\n".join(textwrap.wrap(str(e))) + error = textwrap.indent(error, "\t") + print("\n", error, "\n", file=sys.stderr) + print( + "You may still be able to access the file from the browser:", + file=sys.stderr, + ) + print("\n\t", url_origin, "\n", file=sys.stderr) + return if url is None: print("Permission denied:", url_origin, file=sys.stderr)