The scope of my project is to pass certain values ββfrom a python script to a remote PHP script.
I have a python script that generate an associatve array. For example (already encoded JSON):
{"FRONT": "19.50", "RACK": "17.63", "REAR": "21.06", "ROOM": "15.6"}
I need to pass this associative array to a remote PHP script after this tutorial: http://nonstopblah.wordpress.com/2010/07/13/python-to-php-via-json/
I get 200 for an HTTP response, but in php script the POST variable seems empty
Here is my code:
bulkData = json.dumps(temp, ensure_ascii = 'False') # ensure_ascii is false as data is in unicode and not ascii encoding , use this if data is in any other encoding print bulkData print '\nHTTP Response' headers = { "charset":"utf-8", "Accept": "text/plain"} conn = httplib.HTTPConnection(report_host) postData = urllib.urlencode({'results':bulkData}) conn.request("POST", report_path, postData,headers) response = conn.getresponse() text = response.read() print "Response status: ",response.status,"\n",text conn.close()
this is a php script:
if( isset($_POST['results']) ) { $data = json_decode($_POST['results']); print_r($data); } else { echo 'Nothing to listen.'; print_r($_POST); }
and this is the result of my python script (with deleted answer):
{"FRONT": "20.44", "RACK": "18.88", "REAR": "21.25", "ROOM": "17.7"} HTTP Response Response status: 200 Nothing to listen.Array ( )
is there a smarter way to do this? What am I missing here?
Thank you in advance for your kind answers.