설명서가없는 API로 작업하고 있는데 걸림돌이되었습니다.Python Request Post 발행물
def add_to_publicaster(self):
# function that is called in the background whenever a user signs the petition and opts in to the mailing list
# Makes an API call to publicaster <--- More documentation to follow --->
username = app.config['PUBLICASTER_USERID']
userPass = app.config['PUBLICASTER_PASS']
headers = {'Authorization': {username:userPass}, "Content-type" : "application/json", "Accept":'text/plain'}
url = 'https://api7.publicaster.com/Rest/Subscribers.svc/1?format=json'
data = {"Item": {
"Email": "[email protected]"
}
}
r = requests.post(url, headers = headers, data = data)
단순히이 형식의 POST 요청을 할 생각입니다 :
POST https://api7.publicaster.com/Rest/Subscribers.svc/1?format=json HTTP/1.1
Content-Type: application/json
Authorization: <AccountID>:<Password>
Host: api7.publicaster.com
Content-Length: 64
Expect: 100-continue
Connection: Keep-Alive
{ "Item" : {
"Email" : [email protected]
}
}
기능의 코드는, 그러나, 원하는 요청을 생성하지 않는 나는 기능을 가지고있다. 조언이 도움이 될 것입니다.
무엇을 얻고 있습니까? – thefourtheye
기본적으로 서버에서 요청을 처리하는 중 오류가 발생했다는 매우 긴 오류 메시지입니다. 해결책은 가능한 한 "샘플"요청을 일치시키는 것입니다. – JulianGindi
당신은 json 코드로 데이터를 인코딩해야합니다 ..'json.dumps (dict (data = data))' – karthikr