Dwnloading Big Files,It Stops Dowloanding Without Error

I Need to download monthly Open Library Data Dumps files, they are some big files:

[https://openlibrary.org/data/ol_dump_authors_latest.txt.gz](https://openlibrary.org/data/ol_dump_authors_latest.txt.gz)
[https://openlibrary.org/data/ol_dump_works_latest.txt.gz](https://openlibrary.org/data/ol_dump_works_latest.txt.gz)
[https://openlibrary.org/data/ol_dump_editions_latest.txt.gz](https://openlibrary.org/data/ol_dump_editions_latest.txt.gz)

It hangs downlaoding at worker and edition file because they are big files,the problem i dont get no exception that connection failed.It Just stops Downloading,i know that because the file size wont change for hours

#### First Try
```py
dump_url = "https://openlibrary.org/data/ol_dump_editions_latest.txt.gz"
dump_path =  "temp_file/ol_dump_editions_latest.txt.gz"
session = requests.Session()
    with session.get(dump_url, stream=True) as r:
        r.raise_for_status()
        with open(dump_path, 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024*1024): 
                f.write(chunk)
```

#### Second Try
```py
dump_url = "https://openlibrary.org/data/ol_dump_editions_latest.txt.gz"
dump_path =  "temp_file/ol_dump_editions_latest.txt.gz"
session = requests.Session()
with session.get(dump_url, stream=True) as r:
    r.raise_for_status()
    with open(dump_path, 'wb') as f:
        shutil.copyfileobj(r.raw, f)
```

I got the solutuion, u use timeout and resume download 

##### Main Function
```py
import requests 
from requests.exceptions import ConnectionError
import os

def download_ol_dump_editions_latest(dump_url,dump_path):
    max_download_resumes_count = 0
    with requests.Session() as s:
        try:
            with s.get(dump_url,stream=True,allow_redirects=True,timeout=300) as r:
                r.raise_for_status()
                with open(dump_path, 'wb') as f:
                    last_file_size = None
                    for chunk in r.iter_content(chunk_size=1024*1024):
                        f.write(chunk)
                        f.flush()
                        os.fsync(f.fileno())
        except ConnectionError as to:
            print("Here is Suppose to Timeout")
            resume_download_ol_dump_editions_latest(dump_url=dump_url,dump_path=dump_path,max_d_r_c=max_download_resumes_count)
```

##### Resume Download Function
I put a maximume of downlaod resumes so i dosnt run in a ifint loop
```py
def resume_download_ol_dump_editions_latest(dump_url,dump_path,max_d_r_c):
    print("Im Resuming the Download")
    max_download_resumes = 30
    if max_d_r_c < max_download_resumes:
        max_d_r_c += 1
        print(f"Number of times i resumed: {max_d_r_c}" )
        with open(dump_path, 'ab') as f:
            position = f.tell()
            pos_header = {"Range": f"bytes={position}-"}
        
        with requests.Session() as s:
            try:
                with s.get(dump_url,headers=pos_header,stream=True,allow_redirects=True,timeout=300) as r:
                    r.raise_for_status()
                    with open(dump_path, 'ab') as f:
                        for chunk in r.iter_content(chunk_size=1024*1024):
                            f.write(chunk)
                            f.flush()
                            os.fsync(f.fileno())
            except ConnectionError as to:
                print("Here is Suppose to Timeout")
                resume_download_ol_dump_editions_latest(dump_url=dump_url,dump_path=dump_path,max_d_r_c=max_d_r_c)
```
At the end just run the function 
```py
dump_url = "https://openlibrary.org/data/ol_dump_editions_latest.txt.gz"
    dump_path =  "temp_file/ol_dump_editions_latest.txt.gz"
    download_ol_dump_editions_latest(dump_url=dump_url, dump_path=dump_path)
```