Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve access denied error message #42

Merged
merged 1 commit into from
Mar 24, 2020
Merged
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
19 changes: 18 additions & 1 deletion gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import sys
import tempfile
import textwrap
import time

import requests
Expand Down Expand Up @@ -38,6 +39,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 +91,19 @@ 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:")
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