The Humanitarian Data Exchange(hdx API python)上的配置错误。

huangapple go评论45阅读模式
英文:

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 &quot;/home/user/dashboard/scripts/jhu.py&quot;, line 31, in &lt;module&gt;
    Configuration.create(hdx_site=&quot;prod&quot;, user_agent=&quot;A_Quick_Example&quot;, hdx_read_only=True)
  File &quot;/home/user/anaconda3/lib/python3.8/site-packages/hdx/api/configuration.py&quot;, line 647, in create
    return cls._create(
  File &quot;/home/user/anaconda3/lib/python3.8/site-packages/hdx/api/configuration.py&quot;, line 607, in _create
    cls._configuration.setup_session_remoteckan(remoteckan, **kwargs)
  File &quot;/home/user/anaconda3/lib/python3.8/site-packages/hdx/api/configuration.py&quot;, line 471, in setup_session_remoteckan
    self._session, user_agent = self.create_session_user_agent(
  File &quot;/home/user/anaconda3/lib/python3.8/site-packages/hdx/api/configuration.py&quot;, line 436, in create_session_user_agent
    session = get_session(
  File &quot;/home/user/anaconda3/lib/python3.8/site-packages/hdx/utilities/session.py&quot;, line 173, in get_session
    retries = Retry(
TypeError: __init__() got an unexpected keyword argument &#39;allowed_methods&#39;

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=&#39;prod&#39;, user_agent=&#39;A_Quick_Example&#39;, hdx_read_only=True)

def save(direct):
   datasets = Dataset.read_from_hdx(&#39;novel-coronavirus-2019-ncov-cases&#39;)
   print(datasets.get_date_of_dataset())
   resources = Dataset.get_all_resources(datasets)
    
   for res in resources:
       url, path = res.download(folder=direct)
       print(&#39;Resource URL %s downloaded to %s&#39; % (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")

注意:在代码中,&quot; 被翻译为正常的双引号 ".

英文:

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=&quot;prod&quot;, user_agent=&quot;A_Quick_Example&quot;, 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&quot;Resource URL {url} downloaded to {path}&quot;)


save(&quot;novel-coronavirus-2019-ncov-cases&quot;, &quot;/tmp&quot;)

huangapple
  • 本文由 发表于 2023年2月6日 20:27:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75361308.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定