iT邦幫忙

0

python requests 無法下載

##請問我用requests下載幾個G的檔案,結果到差不多一半就不動了是甚麼原因

from tqdm import tqdm
import requests
url = input()


response = requests.get(url, stream=True)
total_size_in_bytes= int(response.headers.get('content-length', 0))
block_size = 10240 #1 Kibibyte
progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True)
with open(response.headers['Content-Disposition'].split('filename=')[1], 'wb') as file:
    for data in response.iter_content(block_size):
        progress_bar.update(len(data))
        file.write(data)
progress_bar.close()
if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes:
    print("ERROR, something went wrong")
huahualiu iT邦新手 3 級 ‧ 2021-10-16 11:42:06 檢舉
下載甚麼?哪個網站?錯誤訊息是啥?
好歹也講一下
不然中間出問題環節很多
想幫也幫不了你
有試過其他網站?換過網路交叉測試?

尚未有邦友回答

立即登入回答