1

I am trying to programatically download the Bitcoin time series while outputting the download status. I found a lot of online material related to my question, and I was basically copying the code from the accepted answer from this question, but for some reason it doesn't work. It starts downloading but after one or two minutes, the download suddenly stops. Here is my code:

import requests
from tqdm import tqdm

uri2 = "http://api.bitcoincharts.com/v1/csv/bitstampUSD.csv.gz"
with requests.get(uri2, stream=True) as r:
    total_length = int(r.headers.get('content-length'))
    with open("data.csv.gz", "wb") as file:
        for chunk in tqdm(r.iter_content(chunk_size=1024), position=0, leave=True, total=total_length):
            if chunk:
                file.write(chunk)
                # I also tried adding file.flush() here, but the result is the same

Output:

  0%|
| 271787/278309025 [00:28<7:58:27, 9685.15it/s]

Does anyone know why it is not working?

Thanks, Kevin

Kevin Südmersen
  • 883
  • 2
  • 14
  • 24

0 Answers0