Skip to content

Commit

Permalink
HARMONY-1929: Convert opendap get data to post
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnyinverso committed Nov 19, 2024
1 parent 5d218d5 commit 018ff1e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion harmony/harmony.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from enum import Enum
from typing import Any, ContextManager, IO, Iterator, List, Mapping, NamedTuple, Optional, \
Tuple, Generator, Union
from urllib import parse

import curlify
import dateutil.parser
Expand Down Expand Up @@ -1308,10 +1309,17 @@ def _download_file(self, url: str, directory: str = '', overwrite: bool = False)
print(filename)
return filename
else:
data_dict = {}
parse_result = parse.urlparse(url)
is_opendap = parse_result.netloc.startswith('opendap')
method = 'post' if is_opendap else 'get'
if is_opendap: # remove the query params from the URL and convert to dict
url = parse.urlunparse(parse_result._replace(query=""))
data_dict = dict(parse.parse_qsl(parse.urlsplit(url).query))
headers = {
"Accept-Encoding": "identity"
}
with session.get(url, stream=True, headers=headers) as r:
with getattr(session, method)(url, data=data_dict, stream=True, headers=headers) as r:
with open(filename, 'wb') as f:
shutil.copyfileobj(r.raw, f, length=chunksize)
if verbose and verbose.upper() == 'TRUE':
Expand Down

0 comments on commit 018ff1e

Please sign in to comment.