{"Error":"Invalid JSON syntax at offset 2"} - 在尝试获取 everflow 报告时收到此错误

{"Error":"Invalid JSON syntax at offset 2"} - receiving this error while trying to get everflow report

我需要从营销平台 Everflow 获取报告。

代码背后的想法非常简单 - 我提出了一个 POST 请求:

url = "https://api.eflow.team/v1/affiliates/reporting/daily"
headers = {'x-eflow-api-key': '*MY*API*KEY', 'Content-Type': 'application/json',}
payload = '{ "from": "2020-09-01", "to": "2020-09-10", "timezone_id": 67, "currency_id": "USD"}'

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

我得到的结果是:

{"Error":"Invalid JSON syntax at offset 2"}

据我了解,问题可能与有效负载格式有关,但经过两天的尝试,目前还没有成功。

感谢您的帮助!

你能试试下面的代码吗?

import requests
import json
url = "https://api.eflow.team/v1/affiliates/reporting/daily"
headers = {"x-eflow-api-key": "*MY*API*KEY", "Content-type": "application/json"}
payload = {'from': '2020-09-01', 'to': '2020-09-10', 'timezone_id': 67, 'currency_id': 'USD'}
payload = json.dumps(payload)
response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

但是,从请求 2.4.2 开始,支持“json”参数。无需指定“Content-Type”(在大多数情况下)。

requests.post('http://httpbin.org/post', json={'test': 'foo'})