Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Close netcdf dataset after getting its size #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions thredds_crawler/crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def request_xml(url, auth=None):
:param str url: URL for the resource to load as an XML
'''
try:
r = requests.get(url, auth=auth, verify=False)
r = requests.get(url, auth=auth, verify=False, headers={"Connection": "close"})
return r.text.encode('utf-8')
except BaseException:
logger.error("Skipping %s (error parsing the XML)" % url)
Expand Down Expand Up @@ -257,7 +257,7 @@ def __init__(self, dataset_url, auth=None):
self.data_size = None

# Get an etree object
r = requests.get(dataset_url, auth=auth, verify=False)
r = requests.get(dataset_url, auth=auth, verify=False, headers={"Connection": "close"})
try:
tree = etree.XML(r.text.encode('utf-8'))
except etree.XMLSyntaxError:
Expand Down Expand Up @@ -337,6 +337,7 @@ def size(self):
for vname in nc.variables:
var = nc.variables.get(vname)
bites += var.dtype.itemsize * var.size
nc.close()
return bites * 1e-6 # Megabytes
except ImportError:
logger.error("The python-netcdf4 library is required for computing the size of this dataset.")
Expand Down