我使用python requests
发出POST REST请求。
这是代码
REST_URLU = REST_URL+'user/'+get_usermain.username
headers = {'content-type': 'application/json; charset=UTF-8','Accept':'application/json; charset=UTF-8','X-Talisman-Secret':API_KEY}
payload = {"org_name":ORG_KEY,
"first_name":full.first_name.encode('utf8'),
"middle_name" : "ranjan",
"last_name" : "dubey",
"passwd":"9454545",
"city" : "Gwalior",
"state" : "Madhya Pradesh",
"country" : "India",
"pin" : "560068",
"street" : "Cocx town",
"primary_landline" : "080255555",
"primary_mobile":"584644884",
"primary_phon" : "0558877822558",
"primary_email":get_usermain.email.encode('utf8'),
}
print payload
print "resttttttttttttttttt"
print REST_URLU
print "+++++++++++++++++++++++++++++++++"
r = requests.post(REST_URLU, params=payload,headers = headers)
现在问题出在我发布像
这样的身体的时候{"org_name":"45668",
"first_name":"NAME",
"middle_name" : "ranjan",
"last_name" : "dubey",
"passwd":"9454545",
"city" : "Gwalior",
"state" : "Madhya Pradesh",
"country" : "India",
"pin" : "560068",
"street" : "Cocx town",
"primary_landline" : "080255555",
"primary_mobile":"584644884",
"primary_phon" : "0558877822558",
"primary_email":"someemail@hi.com",
}
来自Mozilla REST客户端 它工作得很好。但是当我在Python中使用它时,它不起作用。
租赁帮助我,我可能做错了什么。
答案 0 :(得分:3)
我敢打赌,您需要将内容data=json.dumps(payload)
传递给requests.post()
而不是params
。文档说params
成为url参数,而您希望将其作为JSON编码的邮件正文。