I'm trying to get data from a resource: novel-coronavirus-2019-ncov-cases
from the site Humanitarian Data Exchang. Previously everything was fine, I updated the library hdx-python-api==5.9.7
to the latest version and I get the following error:
Traceback (most recent call last):
File "/home/user/dashboard/scripts/jhu.py", line 31, in <module>
Configuration.create(hdx_site="prod", user_agent="A_Quick_Example", hdx_read_only=True)
File "/home/user/anaconda3/lib/python3.8/site-packages/hdx/api/configuration.py", line 647, in create
return cls._create(
File "/home/user/anaconda3/lib/python3.8/site-packages/hdx/api/configuration.py", line 607, in _create
cls._configuration.setup_session_remoteckan(remoteckan, **kwargs)
File "/home/user/anaconda3/lib/python3.8/site-packages/hdx/api/configuration.py", line 471, in setup_session_remoteckan
self._session, user_agent = self.create_session_user_agent(
File "/home/user/anaconda3/lib/python3.8/site-packages/hdx/api/configuration.py", line 436, in create_session_user_agent
session = get_session(
File "/home/user/anaconda3/lib/python3.8/site-packages/hdx/utilities/session.py", line 173, in get_session
retries = Retry(
TypeError: __init__() got an unexpected keyword argument 'allowed_methods'
Which clearly refers me to a configuration error. I only need to download the data, so I'm using the read configuration example that was given in the official documentation.
Example code:
from hdx.api.configuration import Configuration
from hdx.data.dataset import Dataset
Configuration.create(hdx_site='prod', user_agent='A_Quick_Example', hdx_read_only=True)
def save(direct):
datasets = Dataset.read_from_hdx('novel-coronavirus-2019-ncov-cases')
print(datasets.get_date_of_dataset())
resources = Dataset.get_all_resources(datasets)
for res in resources:
url, path = res.download(folder=direct)
print('Resource URL %s downloaded to %s' % (url, path))
Can you help to solve this error?
Try updating to the latest version of HDX Python API (which is 6.0.9 as of 24/08/2023).
For me, the following code works fine. The code downloads each resource in the dataset from HDX and displays the url that was downloaded along with the path to which the file was downloaded.
from hdx.api.configuration import Configuration
from hdx.data.dataset import Dataset
Configuration.create(hdx_site="prod", user_agent="A_Quick_Example", hdx_read_only=True)
def save(dataset, folder):
dataset = Dataset.read_from_hdx(dataset)
resources = dataset.get_resources()
for res in resources:
url, path = res.download(folder=folder)
print(f"Resource URL {url} downloaded to {path}")
save("novel-coronavirus-2019-ncov-cases", "/tmp")