Note that there are some explanatory texts on larger screens.

plurals
  1. POPass data Python to PHP via JSON
    primarykey
    data
    text
    <p>the scope of my project is to pass certain values from a python script to a remote php script.</p> <p>i've a python script that generate an associatve array. For example (already JSON encoded):</p> <pre><code>{"FRONT": "19.50", "RACK": "17.63", "REAR": "21.06", "ROOM": "15.6"} </code></pre> <p>I need to pass this associative array to a remote PHP script i followed this tutorial: <a href="http://nonstopblah.wordpress.com/2010/07/13/python-to-php-via-json/" rel="nofollow">http://nonstopblah.wordpress.com/2010/07/13/python-to-php-via-json/</a></p> <p>I get 200 for HTTP Response but in the php script the POST variable seems to be empty</p> <p>Here my code:</p> <pre><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() </code></pre> <p>this is the PHP script:</p> <pre><code>if( isset($_POST['results']) ) { $data = json_decode($_POST['results']); print_r($data); } else { echo 'Nothing to listen.'; print_r($_POST); } </code></pre> <p>and this is the output of my python script (with the remote response):</p> <pre><code>{"FRONT": "20.44", "RACK": "18.88", "REAR": "21.25", "ROOM": "17.7"} HTTP Response Response status: 200 Nothing to listen.Array ( ) </code></pre> <p>is there a smarter way to do it? What am i missing here?</p> <p>Thank you in advance for your kind answers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload