Reputation: 41
I have the following code to post using requests module
api_path = r'/DeviceCategory/create'
api_server = (self.base_url + api_path)
logging.info("Triggered API : %s", api_server)
arguments = {"name": "WrongTurn", "vendor": "Cupola", "protocolType": "LWM2M"}
headers = {'content-type': 'application/json;charset=utf-8', 'Accept': '*'}
test_response = requests.post(api_server,headers=headers,cookies=self.jessionid,
timeout=30, json=arguments)
logging.info(test_response.headers)
logging.info(test_response.request)
logging.info(test_response.json())
logging.info(test_response.url)
logging.info(test_response.reason)
The following response i got in header
2017-08-22 12:03:12,811 - INFO - {'Server': 'Apache-Coyote/1.1', 'X-FRAME-OPTIONS': 'SAMEORIGIN, SAMEORIGIN', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, DELETE, PUT', 'Access-Control-Allow-Headers': 'Content-Type', 'Content-Type': 'text/html;charset=utf-8', 'Content-Language': 'en', 'Transfer-Encoding': 'chunked', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'Date': 'Tue, 22 Aug 2017 06:33:12 GMT', 'Connection': 'close'}
And JSON decoding the error
raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Can some please help me out, the status code i got is 500
Upvotes: 0
Views: 2127
Reputation: 1426
It means that the server didn't return any response values (there was no response body, so json() couldn't decode the JSON). Given the 500 error, that probably means that your API call was bad. Not being familiar with the API, I cannot say more but my guess is that you are passing the arguments wrong, try something like:
test_response = requests.post(api_server,headers=headers,cookies=self.jessionid,
timeout=30, data=arguments)
Upvotes: 0