作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试将 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/
我尝试将 ChartMogul 的 API 与 Python 结合使用。由于他们没有客户端库,所以我需要自己做。这是 API 示例: curl -X POST "https://api.chartmo
我是一名优秀的程序员,十分优秀!