Python 错误请求错误调用 Eloqua API - JSON 格式化
Python bad request error calling Eloqua API - JSON formatting
当我尝试使用以下代码访问 Eloqua API 时,出现 400 错误。 Eloqua 支持告诉我以下内容:
"It seems that the 400 error is being caused by an unfamiliar format being using in the request's body. We suggest using the JSON form at advised."
这个调用有什么地方没有将调用主体放在 JSON 格式中吗?我该怎么做?
auth = auth_string.encode('base64','strict')
url='https://secure.p03.eloqua.com/api/bulk/2.0/activities/exports'
data= {"name":"Activity Export Test",
"fields":{
"ActivityId":"{{Activity.Id}}",
},
"filter":"'{{Activity.Type}}'='Subscribe'"}
data2 = json.dumps(data)
headers = {'Authorization': "Basic %s" % auth}
r = requests.post(url, data=data2, headers=headers)
您缺少 Content-Type
header。尝试添加它,如下所示:
headers = {
"Authorization": "Basic %s" % auth,
"Content-Type": "application/json"
}
当我尝试使用以下代码访问 Eloqua API 时,出现 400 错误。 Eloqua 支持告诉我以下内容:
"It seems that the 400 error is being caused by an unfamiliar format being using in the request's body. We suggest using the JSON form at advised."
这个调用有什么地方没有将调用主体放在 JSON 格式中吗?我该怎么做?
auth = auth_string.encode('base64','strict')
url='https://secure.p03.eloqua.com/api/bulk/2.0/activities/exports'
data= {"name":"Activity Export Test",
"fields":{
"ActivityId":"{{Activity.Id}}",
},
"filter":"'{{Activity.Type}}'='Subscribe'"}
data2 = json.dumps(data)
headers = {'Authorization': "Basic %s" % auth}
r = requests.post(url, data=data2, headers=headers)
您缺少 Content-Type
header。尝试添加它,如下所示:
headers = {
"Authorization": "Basic %s" % auth,
"Content-Type": "application/json"
}