简体   繁体   中英

Django: convert cURL to python requests

I have cURL code that I need to convert to python code using requests library. I want to use this inside django backend software. I tried several ways but I am getting some erros. Can someone help me with this? Here is the cURL code:

    curl -XPOST -H 'cache-control: no-cache' -H 'content-type: application/json' -H
'X-Client-Id: asdf1234' -H 'X-Client-Secret: qwer9876' -d '{
"planId":"BASIC", "planName":"Basic subscription plan", "amount":12,
"intervalType":"week", "intervals":2,"description":"This is the standard plan
for our services"}' 'https://test.cashfree.com/api/v2/subscription-plans'

In future, you can use a handy converter like this :

import requests

headers = {
    'cache-control': 'no-cache',
    'content-type': 'application/json',
    'X-Client-Id': 'asdf1234',
    'X-Client-Secret': 'qwer9876',
}

data = '{"planId":"BASIC", "planName":"Basic subscription plan", "amount":12,"intervalType":"week", "intervals":2,"description":"This is the standard planfor our services"}'

response = requests.post('https://test.cashfree.com/api/v2/subscription-plans', headers=headers, data=data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM