2

My task was to write a script that would be transferred from the php variable in python script, there is a variable return, and php variable output. But the problem arose when the return value of the variable (Russian text). Php code:

$hello = 'Виктор';

$result = shell_exec('main.py ' . $hello);

echo $result;

Python code:

# -*- coding: utf-8 -*-
import sys

text = sys.argv[1]


print (text)

Both files in utf-8 without BOM. Tried and .htaccess, it did not help. Result:������. Any idea how this can be fixed a? I w7, python 3.5, editor of np ++.

3
  • I've been struggling with this too for a while. It seems that if I use # -*- coding: Windows-1251 -*- p = "Виктор" print(p) with python 2.x it prints Виктор but with python 3.x I get an error UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-11: ordinal not in range(128) Commented Oct 6, 2015 at 19:11
  • If you find the solution please post it here, I'm sure there's a lot of users with the same problem. Commented Oct 6, 2015 at 19:47
  • hopefully this helps .. Stackoverflow Commented Oct 6, 2015 at 20:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.