Talking about php calling python files

About PHP calling Python data transmission problem

This is a problem that occurred when I was doing a project in college. Now I move it up, hoping to give some small ideas to the future bosses who encounter problems. Please don't carelessly help me correct them. If there is a problem or there is a correction A good solution, I hope everyone can give it, thank you!

In the past, the team carried out project training. Our team chose big data analysis. One of them was to analyze the data input by users after text analysis with python, and then output the corresponding positions and others. The requirement is that the front-end transmits the text request to the back-end PHP, PHP calls the python program for processing, and then transmits the data to PHP, and then to the front-end for the next step of processing. As a result, the data returned by python is garbled on the front end, and the result obtained is completely different from running the python code alone. In a word, an error occurred during the call of the python program by php.

I checked it several times carefully and confirmed that all my PHP and Python encodings are in utf-8 encoding, so there is no doubt about this. So what is the problem? The php call python statement is

$job = "Responsible, good at JAVA";//Incoming text message

$area ='E:/text/sim_str.py';//Address of Python program

cmd=system("python3area 2 C:/Users/Administrator/Desktop/2.txt job",ret);//2 is to locate the error content to this file,

Finally, after many tests, I found that there was a problem with the encoding of the text when it was passed. It should not be UTF-8 encoding. A great god said that this is because the windows system will re-encode the transmitted information by itself. Then I wanted to change the encoding directly, but there was a problem with the python3 encoding change. In the end, my solution is not to transmit through the system, but directly through a third-party database. Both parties call the database. Everything can be solved.

PS: Later, I encountered this kind of problem again. I modified the python code so that it can finally pass only the number directly, and then judge the number at the front end.

The above is the detailed explanation and integration of the php call python file introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time. Thank you very much for your support to the ZaLou.Cn website!

Recommended Posts

Talking about php calling python files
Talking about Python coroutine
Talking about Python functional programming
Talking about inheritance in Python
Talking about strings in Python
Talking about the modules in Python
Talking about Python multithreading and program lock
Python renames files
Learn about Python3 coroutine
Python analysis of wav files
Python reads files by line
python batch run py files
3 ways to encrypt Python files