title: How to download a file (csv.gz) from a url using Python 3.7
body: <p>As with others who have posted in the past, I cannot figure out to download a csv.gz file from a URL in Python 3.7. I see posts but they only post a 2kb file.</p>
  
  <p>I am a 100% newbie using Python.  What follows is the code for one file that I am trying to obtain. I can't even do that. The final goal would be to request all files that start with 2019* using python.  Please try the code below to save the file. As others stated, the file is just a name without the true content - Ref: <a href="https://stackoverflow.com/questions/34561746/downloading-a-csv-gz-file-from-url-in-python">Downloading a csv.gz file from url in Python</a></p>
  
  <pre><code>import requests
  url = 'https://public.bitmex.com/?prefix=data/trade/20191026.csv.gz'
  r = requests.get(url, allow_redirects=True)
  open('20191026.csv.gz', 'wb').write(r.content)
  </code></pre>
  
  <p>Yields:
  Out[40]:
  1245 
  I've tried "wget" and urllib.request along with "urlretrieve" also. </p>
  
  <p>I wish I could add a screenshot or attach a file. The file created is 2kb and not even a csv.gz file. But the true file that I can download from a web browser is 78mb. The file is 20191026.csv.gz not that it matters as they all do the same thing. The location is <a href="https://public.bitmex.com/?prefix=data/trade/" rel="nofollow noreferrer">https://public.bitmex.com/?prefix=data/trade/</a>
  Again, if you know of a way to obtain all the files using a filter such that 2019*csv.gz would be fantastic.</p>