Skip to content

Commit

Permalink
Catch ProxyError in cli.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Apr 13, 2023
1 parent 7217bc9 commit 944659e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
8 changes: 8 additions & 0 deletions gdown/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import textwrap
import warnings

import requests
import six

from . import __version__
Expand Down Expand Up @@ -176,6 +177,13 @@ def main():
indent("\n".join(textwrap.wrap(str(e))), prefix="\t")
)
)
except requests.exceptions.ProxyError as e:
print(
"Failed to use proxy:\n\n{}\n\n"
"Please check your proxy settings.".format(
indent("\n".join(textwrap.wrap(str(e))), prefix="\t")
)
)
except Exception as e:
print(e, file=sys.stderr)
sys.exit(1)
Expand Down
11 changes: 1 addition & 10 deletions gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,7 @@ def download(
is_gdrive_download_link = True

while True:
try:
res = sess.get(url, stream=True, verify=verify)
except requests.exceptions.ProxyError as e:
print(
"An error has occurred using proxy:",
sess.proxies,
file=sys.stderr,
)
print(e, file=sys.stderr)
return
res = sess.get(url, stream=True, verify=verify)

if url == url_origin and res.status_code == 500:
# The file could be Google Docs or Spreadsheets.
Expand Down
10 changes: 1 addition & 9 deletions gdown/download_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import warnings

import bs4
import requests

from .download import _get_session
from .download import download
Expand Down Expand Up @@ -116,14 +115,7 @@ def _download_and_parse_google_drive_link(
else:
url += "?hl=en"

try:
res = sess.get(url, verify=verify)
except requests.exceptions.ProxyError as e:
print(
"An error has occurred using proxy:", sess.proxies, file=sys.stderr
)
print(e, file=sys.stderr)
return False, None
res = sess.get(url, verify=verify)

if res.status_code != 200:
return False, None
Expand Down

0 comments on commit 944659e

Please sign in to comment.