如何在 Python 中使用 API 密钥执行 API 请求

Sam*_*rbo 2 api dictionary screen-scraping key list

所以我一直在尝试访问这个API,但是我需要使用API​​密钥来访问它。我有一个 API 密钥,但我不确定如何格式化所有内容并传输 URL。我的网址如下所示--- https://api.sportsdata.io/v3/nfl/scores/json/Players

我使用的sit也留下了这样的信息:

This is the documentation for SportsDataIO's NFL API. All of our API endpoints can be accessed via an HTTP GET request using your API key. The API key can be passed either as a query parameter or using the following HTTP request header.
Ocp-Apim-Subscription-Key: {key}
Run Code Online (Sandbox Code Playgroud)

不确定这意味着什么,我对数据抓取还很陌生。

如果有人可以提供帮助,那就太好了,谢谢。

chi*_*n88 6

意味着您需要通过标头传递 api 密钥:

import requests

api_key = 'put your api key here'

url = 'https://api.sportsdata.io/v3/nfl/scores/json/Players'
headers = {'Ocp-Apim-Subscription-Key': '{key}'.format(key=api_key)}

jsonData = requests.get(url, headers=headers).json()
Run Code Online (Sandbox Code Playgroud)