将cURL Multi-Form转换为Python



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'},
)

相关内容

  • 没有找到相关文章

最新更新