英文:
Configuration error at The Humanitarian Data Exchange (hdx API python)
问题
I'm trying to get data from a resource: novel-coronavirus-2019-ncov-cases
from the site Humanitarian Data Exchange. 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?
英文:
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?
答案1
得分: 1
尝试升级到最新版本的 HDX Python API(截止到2023年8月24日,版本为6.0.9)。
对我来说,以下代码运行良好。该代码从HDX下载数据集中的每个资源,并显示已下载的URL以及文件的下载路径。
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")
注意:在代码中,"
被翻译为正常的双引号 "
.
英文:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论