简体   繁体   中英

Python bad request error calling Eloqua API - JSON formatting

When I try to access the Eloqua API with the following code, I get a 400 error. Eloqua Support tells me the following:

"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."

Is there something about this call that is not putting the call body in JSON format? How can I do that?

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)

You are missing the Content-Type header. Try adding it, like so:

headers = {
    "Authorization": "Basic %s" % auth,
    "Content-Type": "application/json"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM