如何将CURL转换为Python请求

如何将CURL转换为Python请求,python,curl,python-requests,Python,Curl,Python Requests,我目前正在尝试集成Stripe Connect,遇到了flowing CURl POST请求: curl https://connect.stripe.com/oauth/token \ -d client_secret=SECRET_CODE \ -d code="{AUTHORIZATION_CODE}" \ -d grant_type=authorization_code 然而,我对CURL非常陌生,一直在做一些研究,并试图使用requests包来完成这项工作。这就是我

我目前正在尝试集成Stripe Connect,遇到了flowing CURl POST请求:

curl https://connect.stripe.com/oauth/token \
   -d client_secret=SECRET_CODE \
   -d code="{AUTHORIZATION_CODE}" \
   -d grant_type=authorization_code
然而,我对CURL非常陌生,一直在做一些研究,并试图使用requests包来完成这项工作。这就是我当前的代码:

data = '{"client_secret": "%s", "code": "%s", "grant_type": "authorization_code"}' % (SECRET_KEY, AUTHORIZATION_CODE) 
response = requests.post('https://connect.stripe.com/oauth/token', json=data)

然而,这总是返回一个响应代码400。我不知道我哪里出了问题,任何指导都将得到充分的赞赏

错误是因为您将
数据
作为字符串传递,而不是
请求的
json
param。post
调用希望它是字符串。您的代码应该是:

import requests

data = {
     "client_secret": SECRET_KEY, 
     "code": AUTHORIZATION_CODE, 
     "grant_type": "authorization_code"
} 

response = requests.post('https://connect.stripe.com/oauth/token', json=data)

看看请求库的文档。

您是否真的发送了json?还是纯文本?