Answer the question
In order to leave comments, you need to log in
Why does a PHP+Python script work in the server console, but not in the browser?
I can't get PHP to output lemmatized text in any way. Emptiness is displayed. Everything works in the terminal, but not in the browser. In this case, test.py is displayed, but the value from pystem.py is not.
test.py
text3 = 'привет'
print(text3.encode('utf-8'))
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pymystem3 import Mystem
mystem = Mystem()
text = 'Поехали'
lemmas = mystem.lemmatize(text)
print(''.join(lemmas).encode('utf-8'))
print(text)
<?php
$python = shell_exec('python3 test.py');
echo "printing: " . $python; // выводит b'\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82
$python2 = shell_exec('python3 pystem.py');
echo "printing: " . $python2; // ничего не выводит в браузер
root@214533:/var/www/html/panel/mystemtest# python3 test.py
b'\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82'
root@214533:/var/www/html/panel/mystemtest# python3 pystem.py
b'\xd0\xbf\xd0\xbe\xd0\xb5\xd1\x85\xd0\xb0\xd1\x82\xd1\x8c\n'
root@214533# php test.php
<br>pystem.py result: поехать
root@214533:/var/www/html/mystemtest# sudo -u www-data php test.php
Installing mystem to /root/.local/bin/mystem from http://download.cdn.yandex.net/mystem/mystem-3.1-linux-64bit.tar.gz
Traceback (most recent call last):
File "pystem.py", line 7, in <module>
mystem = Mystem()
File "/usr/local/lib/python3.6/dist-packages/pymystem3/mystem.py", line 178, in __init__
autoinstall()
File "/usr/local/lib/python3.6/dist-packages/pymystem3/mystem.py", line 57, in autoinstall
install(out)
File "/usr/local/lib/python3.6/dist-packages/pymystem3/mystem.py", line 74, in install
os.makedirs(MYSTEM_DIR)
File "/usr/lib/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/usr/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/root/.local'
Answer the question
In order to leave comments, you need to log in
root directory is different most likely, log/look for errors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question