requests response.iter_content() gets incomplete file ( 1024MB instead of 1.5GB )?

后端 未结 3 1901
醉梦人生
醉梦人生 2021-02-13 21:46

hi i have been using this code snippet to download files from a website, so far files smaller than 1GB are all good. but i noticed a 1.5GB file is incomplete

# s         


        
3条回答
  •  有刺的猬
    2021-02-13 22:16

    Please double check that you can download the file via wget and/or any regular browser. It could be restriction on the server. As I see your code can download big files (bigger then 1.5Gb)

    Update: please try to inverse the logic - instead of

    if chunk: # filter out keep-alive new chunks                                                                                                                                                                                                         
        f.write(chunk)                                                                                                                                                                                                                                   
        f.flush()
    

    try

    if not chunk:
       break
    
    f.write(chunk)                                                                                                                                                                                                                                   
    f.flush()
    

提交回复
热议问题