Python - 请求未通过使用请求和 json 授权
Python - Request not authorized by using requests and json
我一直在使用代码 python 访问这种 url https://api.elsevier.com/analytics/scival/institution/metrics?metricTypes=ScholarlyOutput&institutionIds=508175%2C508076&yearRange=5yrs&includeSelfCitations=true&byYear=true&includedDocs=AllPublicationTypes&journalImpactType=CiteScore&showAsFieldWeighted=false&apiKey=7f59af901d2d86f78a1fd60c1bf9426a
这是 public json url Elsevier Developer Portal
我一直在使用的小代码是这样的:
import requests
import json
url = "https://api.elsevier.com/analytics/scival/institution/metrics?metricTypes=ScholarlyOutput&institutionIds=508175%2C508076&yearRange=5yrs&includeSelfCitations=true&byYear=true&includedDocs=AllPublicationTypes&journalImpactType=CiteScore&showAsFieldWeighted=false&apiKey=7f59af901d2d86f78a1fd60c1bf9426a"
with requests.Session() as s:
data = s.get(url).json()
一切正常,直到今天我的项目在执行此代码时出错,如果我只 运行 s.get(url).text
然后我收到以下消息
'Request not authorized. Please specify a valid API key or HMAC signature.'
我不得不说我什至有自己的 api_key 和 access_token,但即使使用它们我也得到相同的信息。
所以,我需要一些帮助来设法提取数据,因为数据仍在 link https://api.elsevier.com/analytics/scival/institution/metrics?metricTypes=ScholarlyOutput&institutionIds=508175%2C508076&yearRange=5yrs&includeSelfCitations=true&byYear=true&includedDocs=AllPublicationTypes&journalImpactType=CiteScore&showAsFieldWeighted=false&apiKey=7f59af901d2d86f78a1fd60c1bf9426a
中(只是 google 并且会看到它)。
希望一些指导来做到这一点,因为直到昨天还没有错误。
我已经检查了文档,您在请求中缺少 header。
以下代码有效。
import requests
url = "https://api.elsevier.com/analytics/scival/institution/metrics?metricTypes=ScholarlyOutput&institutionIds=508175%2C508076&yearRange=5yrs&includeSelfCitations=true&byYear=true&includedDocs=AllPublicationTypes&journalImpactType=CiteScore&showAsFieldWeighted=false&apiKey=7f59af901d2d86f78a1fd60c1bf9426a"
payload={}
headers = {
'Accept': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
我一直在使用代码 python 访问这种 url https://api.elsevier.com/analytics/scival/institution/metrics?metricTypes=ScholarlyOutput&institutionIds=508175%2C508076&yearRange=5yrs&includeSelfCitations=true&byYear=true&includedDocs=AllPublicationTypes&journalImpactType=CiteScore&showAsFieldWeighted=false&apiKey=7f59af901d2d86f78a1fd60c1bf9426a
这是 public json url Elsevier Developer Portal
我一直在使用的小代码是这样的:
import requests
import json
url = "https://api.elsevier.com/analytics/scival/institution/metrics?metricTypes=ScholarlyOutput&institutionIds=508175%2C508076&yearRange=5yrs&includeSelfCitations=true&byYear=true&includedDocs=AllPublicationTypes&journalImpactType=CiteScore&showAsFieldWeighted=false&apiKey=7f59af901d2d86f78a1fd60c1bf9426a"
with requests.Session() as s:
data = s.get(url).json()
一切正常,直到今天我的项目在执行此代码时出错,如果我只 运行 s.get(url).text
然后我收到以下消息
'Request not authorized. Please specify a valid API key or HMAC signature.'
我不得不说我什至有自己的 api_key 和 access_token,但即使使用它们我也得到相同的信息。
所以,我需要一些帮助来设法提取数据,因为数据仍在 link https://api.elsevier.com/analytics/scival/institution/metrics?metricTypes=ScholarlyOutput&institutionIds=508175%2C508076&yearRange=5yrs&includeSelfCitations=true&byYear=true&includedDocs=AllPublicationTypes&journalImpactType=CiteScore&showAsFieldWeighted=false&apiKey=7f59af901d2d86f78a1fd60c1bf9426a
中(只是 google 并且会看到它)。
希望一些指导来做到这一点,因为直到昨天还没有错误。
我已经检查了文档,您在请求中缺少 header。
以下代码有效。
import requests
url = "https://api.elsevier.com/analytics/scival/institution/metrics?metricTypes=ScholarlyOutput&institutionIds=508175%2C508076&yearRange=5yrs&includeSelfCitations=true&byYear=true&includedDocs=AllPublicationTypes&journalImpactType=CiteScore&showAsFieldWeighted=false&apiKey=7f59af901d2d86f78a1fd60c1bf9426a"
payload={}
headers = {
'Accept': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)