在发送请求时,需要将API密钥作为authorization标头的值发送。以下是一个示例代码:
import requests
API_KEY = "your-api-key"
headers = {
"authorization": "Bearer " + API_KEY
}
response = requests.post("https://api.example.com/endpoint", headers=headers, data={})
在代码中,API密钥被存储在一个变量中。然后,在请求中,添加一个名为“authorization”的标头,并将它的值设置为“Bearer”加上API密钥。这将告诉API服务您的密钥,并且能够成功地使用它。