import requests
from requests.exceptions import RequestException
ダウンロード
シンプル
response = requests.get(URL)
if response.status_code == 200: with open(パス, 'wb') as fw: for chunk in response.iter_content(chunk_size=100000): fw.write(chunk)
try:
response = requests.get(URL, timeout=10) response.raise_for_status() with open(パス, 'wb') as fw: for chunk in response.iter_content(chunk_size=100000): fw.write(chunk)
print(f'{URL} のダウンロードが成功しました') except RequestException as e: print(f'{URL} のダウンロード中にエラーが発生しました: {e}')