Skip to content

Commit

Permalink
Retrieve access denied error message
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Mar 24, 2020
1 parent a092769 commit 0dc5fe4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def get_url_from_gdrive_confirmation(contents):
url = url.replace("\\u003d", "=")
url = url.replace("\\u0026", "&")
return url
m = re.search('<p class="uc-error-subcaption">(.*)</p>', line)
if m:
error = m.groups()[0]
raise RuntimeError(error)


def download(url, output=None, quiet=False, proxy=None, speed=None):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0dc5fe4

Please sign in to comment.