title: How to download netCDF4 file from webpage?
body: <p>I want to download a netCDF4 file from a webpage. I can download the datafile, but there seems to be some errors in the file I downloaded using following codes:</p>
  <pre><code>import requests
  from netCDF4 import Dataset
  
  
  def download_file(url):
      local_filename = url.split('/')[-1]
      with requests.get(url, stream=True) as r:
          with open(local_filename, 'wb') as f:
              shutil.copyfileobj(r.raw, f)
  
      return local_filename
  
  
  url = 'https://smos-diss.eo.esa.int/oads/data/SMOS_Open_V7/SM_REPR_MIR_SMUDP2_20191222T183243_20191222T192549_700_300_1.nc'
  local_filename = download_file(url)
  sm_nc = Dataset(local_filename)
  
  </code></pre>
  <p>But finally I got error message:</p>
  <pre><code>Traceback (most recent call last):
  
    File &quot;&lt;ipython-input-98-809c92d8bce8&gt;&quot;, line 1, in &lt;module&gt;
      sm_nc = Dataset(local_filename)
  
    File &quot;netCDF4/_netCDF4.pyx&quot;, line 2321, in netCDF4._netCDF4.Dataset.__init__
  
    File &quot;netCDF4/_netCDF4.pyx&quot;, line 1885, in netCDF4._netCDF4._ensure_nc_success
  
  OSError: [Errno -51] NetCDF: Unknown file format: b'SM_REPR_MIR_SMUDP2_20191222T183243_20191222T192549_700_300_1.nc'
  </code></pre>
  <p>I also simply tried <code>urllib.request.urlretrieve(url, './1.nc')</code>, then <code>sm_nc = Dataset('./1.nc')</code>, but just got the following error message:</p>
  <pre><code>Traceback (most recent call last):
  
    File &quot;&lt;ipython-input-101-61d1f577421e&gt;&quot;, line 1, in &lt;module&gt;
      sm_nc = Dataset('./1.nc')
  
    File &quot;netCDF4/_netCDF4.pyx&quot;, line 2321, in netCDF4._netCDF4.Dataset.__init__
  
    File &quot;netCDF4/_netCDF4.pyx&quot;, line 1885, in netCDF4._netCDF4._ensure_nc_success
  
  OSError: [Errno -51] NetCDF: Unknown file format: b'./1.nc'
  </code></pre>
  <p>But the thing is that, if I paste the <code>url</code> in the search box of my Safari or Chrome, then click <code>download</code>, the file I got is readable by <code>netCDF4.Dataset</code>. (You could also try that.) I tried with many other solutions but didn't work. So is there anybody who could do me a favour? Thanks!
  By the way, the <code>requests</code> and <code>netCDF4</code> I am using are of version <code>2.26.0</code> and <code>1.5.3</code>, <code>urllib.request</code> is of <code>3.7</code>.</p>