Trying to POST json data from Python to PHP

I modified http://fivefilters.org/term-extraction/ this project to:

This input (https://gist.github.com/4426264) of the python script term-extraction.py text outputs keywords in json format and sends the term-extraction.py → echo.php file through POST json to php

link to term-extraction.py https://gist.github.com/4426181 link to echo.php https://gist.github.com/4426193

here is the json output specified by the php script: https://gist.github.com/4426197 here is the expression term -extraction.py: http://jsfiddle.net/Bw7UX/

here is the desired output of the array that I would like to pass to php: https://gist.github.com/4426208

So my problem is that:

Array ( [json] => None ) 

I would like the php array to have the meaning of all keywords from a python script, like this link: https://gist.github.com/4426208

 array(42) { [0]=> string(10) "rajaratnam" [1]=> string(5) "court" [2]=> string(14) "district court" ... [41]=> string(6) "appeal" } 

I think my problem could be with line 69 to 78 term-extraction.py and in particular with this line:

 mydata=[('json', self.response.out.write(json.dumps(list, indent=0)))] #trying to create an 

Thanks for your answers, I am very new to python, so I appreciate patience.

edit: This is the result when the script is run. I don't understand why json is outputting a python script from them, but it is not in the PHP array correctly. `START echo.php

Null

json echo: POPS: NO POPS array () END echo.php

Status: 200 OK Cache-Control: no-cache Content-Type: text / plain Expires: Fri, Jan 01, 1990 00:00:00 GMT Content-Length: 533 {"json": ["rajaratnam", "court", "district court", "sec", "court documents", "securities fraud", "court documents", "group of galleons", "exchange commission", "sakti prasad", "us", "case", " judgment "," group "," securities "," gupta "," district "," sakti "," right "," co "," founder "," fines "," raj "," consulting "," days "," manager "," conspiracy "," year "," years "," prasad "," inc "," network "," lawsuit "," editing "," against "," sax "," galleon ", “commission”, “reuters”, “documents”, “advice”, “appeal”]} `

0
source share
2 answers

It seems the self.response.out.write function returns None. I think in line 69 you should:

 mydata = json.dumps({'json': list}, indent=0) 
+1
source

I am not familiar with python but am trying to help.

Are you sure you transcoded "json data" as a "string" before sending it to php? Try passing the gated strings ({'name': 'Alex'}) and see what happens at the php end.

0
source

Source: https://habr.com/ru/post/1444527/


All Articles