cURL:
curl 'https://api.flaticon.com/v3/app/authentication'
-H 'Content-Type: multipart/form-data'
-H 'Accept: application/json'
-F apikey=PRIVATE_KEY
Response:
{"data":{"token":"TOKEN","expires":1680693480}}`
具有完全相同PRIVATE_KEY的Python代码抛出403,对于我的生命,我无法弄清楚为什么:
headers = {
'Content-Type': 'multipart/form-data',
'Accept': 'application/json',
}
files = {
'apikey': (None, 'PRIVATE_KEY'),
}
response = requests.post('https://api.flaticon.com/v3/app/authentication', headers=headers, files=files)
print(response)
cURL的-F
不是file
,而是form
;映射到requests.post(..., data=...)
。
很可能你也不需要multipart/form-data
头。
headers = {
'Accept': 'application/json',
}
response = requests.post(
'https://api.flaticon.com/v3/app/authentication',
headers=headers,
data={'apikey': 'PRIVATE_KEY'},
)