diff --git a/tools/file_downloader.py b/tools/file_downloader.py index 06aab7cd..ac974035 100644 --- a/tools/file_downloader.py +++ b/tools/file_downloader.py @@ -98,12 +98,15 @@ def __init__(self, url, save_path, max_thead_num = 8, callback=None, force_write self.callback = callback self.data_content = None headers = self.headers.copy() - res = requests.head(self.url, headers=headers) - # 302 redirect - if res.status_code == 302: - self.url = res.headers['Location'] - print(f"redirect to {self.url}") + while 1: res = requests.head(self.url, headers=headers) + # 302 redirect + if res.status_code == 302 or res.status_code == 301: + self.url = res.headers['Location'] + print(f"redirect to {self.url}") + res = requests.head(self.url, headers=headers) + else: + break if res.status_code != 200: raise Exception("download file error, code: {}, content: {}".format(res.status_code, res.content.decode())) try: