gpt4 book ai didi

python - 在 ChartMogul API 上使用 Python 请求

转载 作者:行者123 更新时间:2023-12-01 03:36:06 26 4
gpt4 key购买 nike

我尝试将 ChartMogul 的 API 与 Python 结合使用。由于他们没有客户端库,所以我需要自己做。这是 API 示例:

curl -X POST "https://api.chartmogul.com/v1/import/customers" \
-u YOUR_ACCOUNT_TOKEN:YOUR_SECRET_KEY \
-H "Content-Type: application/json" \
-d '{
"data_source_uuid": "ds_fef05d54-47b4-431b-aed2-eb6b9e545430",
"external_id": "cus_0001",
"name": "Adam Smith",
"email": "adam@smith.com",
"country": "US",
"city": "New York"
}'

这就是我所做的:

import requests

url = "https://api.chartmogul.com/v1/import/customers"
data_source_uuid = "the uuid I get from my api data source"
token = 'my token'
key= 'my key'
payload = {
"data_source_uuid": data_source_uuid,
"external_id": "cus_0001",
"name": "Adam Smith",
"email": "adam@smith.com",
"country": "US",
"city": "New York"
}

headers = {"Content-Type": "application/json"}
res = requests.post(url,
auth=(token, key),
data=payload,
headers=headers)

但是我收到了 400 响应(错误请求)。这是什么问题?

最佳答案

尝试

data=json.dumps(payload),

而不是

data=payload,

关于python - 在 ChartMogul API 上使用 Python 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40377684/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com