1

I am trying to pass data in json format from a python script in Raspberry Pi 2 to a web service. I have tried the following code:

import json 
import requests
import pprint
url = 'http://192.168.1.101/TestWebsite/api/SecondlyReadingDatas'
data = {'ID': '1', "ChannelID': '34','TimeStampID': '45}
data_json=json.dumps(data)
headers = {'Content-type': 'applcation/json'}
response = requests.post(url, json=data)
pprint.pprint(response.json))

However, I am getting the following error:

{u'Message':u'An error has occured'}

I have also tried changing the response = requests.post(url, json=data)toresponse = requests.post(url, data=data_json, headers=headers)

I referenced my python code from the following link:

REST post using Python-Request

I am however, still getting the same error message. I have no idea how to debug it since it does not display what kind of error. Would appreciate any help

gram95
  • 103
  • 2
  • 15
  • Please check out [https://stackoverflow.com/questions/7172784/how-to-post-json-data-with-curl-from-terminal-commandline-to-test-spring-rest/40072362#40072362] – Amit Vujic Sep 05 '17 at 17:28

0 Answers0