{“错误”:“在偏移量2处无效的JSON语法”}}-尝试获取Everflow报告时收到此错误

问题描述

我需要从营销平台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'})

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...