为什么是Healthsites.io API调用失败?



我正在给卫生站打电话。获取给定区域内的站点。但到目前为止,我的API调用一直失败,尽管使用https://healthsites.io/api/docs/上的"源代码"下列出的格式进行python调用。当我使用以下函数时:

import pandas as pd
import time
import requests
import json
import coreapi
def getHealthcare(APIkey):

# Initialize a client & load the schema document
client = coreapi.Client()
schema = client.get("https://healthsites.io/api/docs/")
# Interact with the API endpoint
action = ["api", "v2 > facilities > list"]
params = {
"api-key": APIkey,
"page": 1
#"country": ...,
#"extent": ,
#"output": ...,
#"from": ...,
#"to": ...,
#"flat-properties": ...,
#"tag-format": ...,
}

result = client.action(schema, action, params=params)
df = pd.json_normalize(result) # normalize json file into pandas
if not df.empty: # If there ARE results, continue
return df
print(getHealthcare('INSERT API HERE'))

我得到以下错误/回溯:

Traceback (most recent call last):
File "C:Usersusernameanaconda3libsite-packagescoreapiclient.py", line 34, in _lookup_link
node = node[key]
File "C:Usersusernameanaconda3libsite-packagesitypes.py", line 115, in __getitem__
return self._data[key]
KeyError: 'v2 > facilities > list'

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersusernameOneDriveDocumentsGitHubasset-mapprAssetMapprdatabaseNationalgetHealthsites.py", line 44, in <module>
print(getHealthcare('INSERT API HERE'))
File "C:UsersusernameOneDriveDocumentsGitHubasset-mapprAssetMapprdatabaseNationalgetHealthsites.py", line 38, in getHealthcare
result = client.action(schema, action, params=params)
File "C:Usersusernameanaconda3libsite-packagescoreapiclient.py", line 163, in action
link, link_ancestors = _lookup_link(document, keys)
File "C:Usersusernameanaconda3libsite-packagescoreapiclient.py", line 38, in _lookup_link
raise exceptions.LinkLookupError(msg % (index_string, repr(key).strip('u')))
LinkLookupError: Index ['api']['v2 &gt; facilities &gt; list'] did not reference a link. Key 'v2 &gt; facilities &gt; list' was not found.

看看coreapi文档,我想你想要这样的东西:

action = ["api", "v2", "facilities", "list"]
params = {...}
result = client.action(schema, action, params=params)

如果我们启用调试日志记录,我们可以看到它生成如下所示像一个合理的请求:

>>> import logging
>>> logging.basicConfig(level='DEBUG')
>>> client.action(schema, ['api', 'v2', 'facilities', 'list'], params={'api-key': 'foo', 'page': 1})
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (2): healthsites.io:443
DEBUG:urllib3.connectionpool:https://healthsites.io:443 "GET /api/v2/facilities/?api-key=foo&page=1 HTTP/1.1" 502 None

最新更新