File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -61,18 +61,20 @@ def check_integrity(fpath: str, md5: Optional[str] = None) -> bool:
6161 return check_md5 (fpath , md5 )
6262
6363
64- def _get_redirect_url (url : str , max_hops : int = 10 ) -> str :
65- import requests
66-
67- for hop in range (max_hops + 1 ):
68- response = requests .get (url )
64+ def _get_redirect_url (url : str , max_hops : int = 3 ) -> str :
65+ initial_url = url
66+ headers = {"Method" : "HEAD" , "User-Agent" : USER_AGENT }
6967
70- if response .url == url or response .url is None :
71- return url
68+ for _ in range (max_hops + 1 ):
69+ with urllib .request .urlopen (urllib .request .Request (url , headers = headers )) as response :
70+ if response .url == url or response .url is None :
71+ return url
7272
73- url = response .url
73+ url = response .url
7474 else :
75- raise RecursionError (f"Too many redirects: { max_hops + 1 } )" )
75+ raise RecursionError (
76+ f"Request to { initial_url } exceeded { max_hops } redirects. The last redirect points to { url } ."
77+ )
7678
7779
7880def _get_google_drive_file_id (url : str ) -> Optional [str ]:
You can’t perform that action at this time.
0 commit comments