为什么healthsites.io api呼叫失败?
我正在尝试打电话给HealthSites.io,以获取给定区域的站点。但是到目前为止,我的API呼叫已经失败了,尽管使用了用于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:\Users\username\anaconda3\lib\site-packages\coreapi\client.py", line 34, in _lookup_link
node = node[key]
File "C:\Users\username\anaconda3\lib\site-packages\itypes.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:\Users\username\OneDrive\Documents\GitHub\asset-mappr\AssetMappr\database\National\getHealthsites.py", line 44, in <module>
print(getHealthcare('INSERT API HERE'))
File "C:\Users\username\OneDrive\Documents\GitHub\asset-mappr\AssetMappr\database\National\getHealthsites.py", line 38, in getHealthcare
result = client.action(schema, action, params=params)
File "C:\Users\username\anaconda3\lib\site-packages\coreapi\client.py", line 163, in action
link, link_ancestors = _lookup_link(document, keys)
File "C:\Users\username\anaconda3\lib\site-packages\coreapi\client.py", line 38, in _lookup_link
raise exceptions.LinkLookupError(msg % (index_string, repr(key).strip('u')))
LinkLookupError: Index ['api']['v2 > facilities > list'] did not reference a link. Key 'v2 > facilities > list' was not found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 coreapi documentation ,我想您想要类似的东西:
如果我们启用debug记录,我们可以看到这会生成外观
就像一个合理的请求:
Looking at the coreapi documentation, I think you want something like:
If we enable debug logging, we can see that this generates what looks
like a reasonable request: