首页 > 解决方案 > Python(Django)获取响应API不起作用

问题描述

我的代码无法将数据发布到 Get Response: Getting authentication errors on the headers (Response on terminal)。已与 GR 交谈,他们可以看到流量,但建议代码错误。

这是POST代码:

import requests
from django.db import models
from elissa.functions import get_async_web_response, get_async_web_response_no_decode 

def post_lead(self):
    data = '{ "name": "' + self.first_name + '", "email": "' + self.email + '", "campaign": { "campaignId": "xxxxx" }, "ipAddress": "' + self.ip + '",  }' 
    headers = {"X-Auth-Token": "api-key xxxxxxxxxxxx","Content-Type": "application/json"}
    get_async_web_response_no_decode("https://api.getresponse.com/v3/contacts", "POST", data=data, headers=headers)
    print "post lead data: " + data 
    headers = requests.post('https://api.getresponse.com/v3/contacts')
    print headers.content
    response = requests.get('https://api.getresponse.com/v3/contacts')
    print response.content

以下是错误日志:

This is the error i get back:{
"httpStatus": 400,
"code": 1021,
"codeDescription": "There is something wrong with your request headers",
"message": "Unsupported `ContentType` header.",
"moreInfo": "https://apidocs.getresponse.com/en/v3/errors/1021",
"context": {
    "sentHeaderValue": "",
    "supportedHeaderValues": [
        "application/json",
        "application/x-www-form-urlencoded",
        "multipart/form-data"
    ]
},
"uuid": "edaa9637-2fb0-4933-9da6-f2b3bacfeaf2"

} { "httpStatus": 401, "code": 1014, "codeDescription": "身份验证过程中出现问题,检查标头!", "message": "不支持的身份验证方法", "moreInfo": " https://apidocs. getresponse.com/en/v3/errors/1014 ", "context": [], "uuid": "a0af5b3f-101e-41de-b6b8-bba310bd40ba"

希望您能提供帮助,如果您需要更多信息,请告诉我。

干杯

标签: pythondjangoapi-design

解决方案


推荐阅读