我在使用 ScienceDirect API 时遇到问题并寻求帮助。 在我使用带有 requests.get 的 API 之前,一切都运行良好。 由于我的搜索字符串发生了一些变化,我被迫使用 put 方法(他们的 API 支持告诉我这一点)。
这是我的代码:
headers = {}
headers['Accept']='application/json'
headers['X-ELS-APIKey'] = 'my Api code here'
headers['X-ELS-Insttoken'] = 'my institutional token here'
headers['Content-Type'] = 'application/json'
data = {
'qs':'("blockchain" OR "distributed ledger" OR "DLT") AND ("circular economy" OR "sustainable supply chain“)',
'offset': 0
}
Url = "https://api.elsevier.com/content/search/sciencedirect"
r = requests.put(Url, data =json.dumps(data), headers=headers)
print(r.url)
我按照此处的文档进行操作:https://dev.elsevier.com/documentation/ScienceDirectSearchAPI.wadl 当我运行此代码时,我收到错误消息
{"service-error":{"status":{"statusCode":"AUTHENTICATION_ERROR","statusText":"没有为请求提供 APIKey"}}}
我的 apiKey 和机构令牌是正确的,并且我看到它在标头中提交了它们。 您知道为什么会出现此错误吗?我提交的标题是否不正确?
实际上这个错误发生在您的网站地址上。在 science direct 上,您必须注册您的网站地址才能获取您的 Api_key,然后如果您想在本地系统中测试您的 Api_key,则它不起作用。 我建议你:
可以给我你之前使用GET方法时使用的代码吗?