I had a similar problem and solved it as follows. I donβt understand why this is necessary, because I have already processed everything with UTF-8. Calling my Python script from the command line worked, but not with exec (shell_exec) via PHP and Apache.
According to the php forum entry , this one is needed if you want to use escapeshellarg() :
setlocale(LC_CTYPE, "en_US.UTF-8");
It must be called before executing escapeshellarg() . In addition, it was necessary to set a specific Python environment variable before the command exe (found an unrelated hint here ):
putenv("PYTHONIOENCODING=utf-8");
My Python script evaluated the arguments like this:
sys.argv[1].decode("utf-8")
(Hint: this was necessary because I use the library to convert some Arabic texts.)
So, finally, I could imagine that the initial question could be resolved as follows:
setlocale(LC_CTYPE, "en_US.UTF-8"); putenv("PYTHONIOENCODING=utf-8"); $tables = shell_exec('/s/python-2.6.2/bin/python2.6 getWikitables.py ' . escapeshellarg($title));
But I can not say anything about the return value. In my case, I could easily output it to the browser.
Spent many, many hours to figure it out ... One of the situations when I hate my job ;-)
source share