Accept-Encoding: gzip,deflate I am currently integrating a REST based web services into my program. The REST services are tested with soapUI. All the REST end points are working fine. But when we integrate the REST services into python based client program we are facing issue with POST request. I have tried using urllib2, requests, httplib modules..
urllib2 implementation
import urllib2
import urllib
url = "https://serverip.com/webapi/object1/"
values = {
"owner": 1,
"parent": 1,
"region": 7,
"pod_identifier": "EMEMASTER1",
"type": "S",
"number": 1,
"description": "TESTTTTT",
}
data = urllib.urlencode(values)
req = urllib2.Request(url)
req.add_data(data)
req.add_header("Authorization", "Token as123131231231312312321asddasd43532y5456#$%#$")
response = urllib2.urlopen(req)
res = response.read()
print res
Result
File "tester.py", line 24, in <module>
response = urllib2.urlopen(req)
File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.6/urllib2.py", line 397, in open
response = meth(req, response)
File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.6/urllib2.py", line 435, in error
return self._call_chain(*args)
File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: BAD REQUEST
I am facing the same issue while using requests and httplib2 but the soapUI request works fine.
Can anyone help me to understand the problem?
/Shan