Всем привет, я хочу скачать видео таким кодом:
def download_video(video_list):
counter = 1
for video in video_list:
video_id = get_video_id(url_video=video[0])
response = urllib.request.urlopen(f"https://drive.google.com/uc?id={video_id}&export=download").read()
try:
with open(f"videos/{counter}.mp4", "wb") as file:
file.write(response)
counter += 1
except Exception:
return "Видео не загрузилось"
Но выдает такую ошибку
Traceback (most recent call last):
File "C:\Users\mihai\Desktop\uiautomator\main.py", line 81, in <module>
download_video(video_list=video_list)
File "C:\Users\mihai\Desktop\uiautomator\main.py", line 36, in download_video
response = urllib.request.urlopen(f"https://drive.google.com/uc?id={video_id}&export=download").read()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\mihai\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\mihai\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 525, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\mihai\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 634, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "C:\Users\mihai\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 563, in error
return self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\mihai\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "C:\Users\mihai\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
Но при этом скачивая одно видео, следующим способом, все хорошо:
response = urllib.request.urlopen("https://drive.google.com/uc?id=1w1kXQ52gTIN6L_Pw8_bLpSa5D2zc4PlN&export=download")
with open("1.mp4", "wb") as file:
file.write(response.read())