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 @@ -67,18 +67,20 @@ def check_integrity(fpath: str, md5: Optional[str] = None) -> bool:
67
67
return check_md5 (fpath , md5 )
68
68
69
69
70
- def _get_redirect_url (url : str , max_hops : int = 10 ) -> str :
71
- import requests
72
-
73
- for hop in range (max_hops + 1 ):
74
- response = requests .get (url )
70
+ def _get_redirect_url (url : str , max_hops : int = 3 ) -> str :
71
+ initial_url = url
72
+ headers = {"Method" : "HEAD" , "User-Agent" : USER_AGENT }
75
73
76
- if response .url == url or response .url is None :
77
- return url
74
+ for _ in range (max_hops + 1 ):
75
+ with urllib .request .urlopen (urllib .request .Request (url , headers = headers )) as response :
76
+ if response .url == url or response .url is None :
77
+ return url
78
78
79
- url = response .url
79
+ url = response .url
80
80
else :
81
- raise RecursionError (f"Too many redirects: { max_hops + 1 } )" )
81
+ raise RecursionError (
82
+ f"Request to { initial_url } exceeded { max_hops } redirects. The last redirect points to { url } ."
83
+ )
82
84
83
85
84
86
def _get_google_drive_file_id (url : str ) -> Optional [str ]:
You can’t perform that action at this time.
0 commit comments