Reputation: 2811
I am using python requests
to make a POST REST request .
Here is code
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)
Now the problem is whenever i am posting the same body like
{"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":"[email protected]",
}
From Mozilla REST client It is working fine .But the same Body when I am using in Python it is not working .
lease help me What might I am doing wrong .
Upvotes: 0
Views: 63
Reputation: 26160
My bet is that you need to pass your content as data=json.dumps(payload)
to requests.post()
instead of as params
. Docs say that params
become url parameters, whereas you want this as a JSON-encoded message body.
Upvotes: 3