uWSGI python子进程chrome/firefox失败 [英] uWSGI python subprocess chrome/firefox failed
问题描述
我在使用nginx的uWSGI下有一个python flask应用程序.
python代码调用subprocess.Popen()
来运行浏览器(即Firefox,Chrome),但uWSGI日志显示错误.
该错误与linux(ubuntu)标准命令有关,即readlink
,which
,cat
和其他命令.
I have a python flask app under uWSGI served using nginx.
The python code calls subprocess.Popen()
to run a browser (i.e. Firefox, Chrome) but the uWSGI log shows errors.
The error is related to linux(ubuntu) standard commands i.e. readlink
, which
, cat
and others.
我怀疑这与用户访问权限有关,但不确定.
uWSGI服务使用我的用户和www-data
组运行.
I am suspecting this is user access related, but not sure.
The uWSGI service runs using my user and www-data
group.
Python代码
import subprocess
@app.route('/api/check/version', methods=['POST'])
def check_version():
pid = subprocess.Popen(['/usr/bin/firefox', '--version'], stdout=subprocess.PIPE)
#pid = subprocess.Popen(['/usr/bin/google-chrome', '--version'], stdout=subprocess.PIPE)
data = pid.communicate()
return data
if __name__ == "__main__":
check_version()
uWSGI日志
**in case of doing Popen for /usr/bin/firefox
/usr/bin/firefox: 1: /usr/bin/firefox: which: not found
**in case of doing Popen for /usr/bin/google-chrome
/usr/bin/google-chrome-stable: line 8: readlink: command not found
/usr/bin/google-chrome-stable: line 10: dirname: command not found
/usr/bin/google-chrome-stable: line 46: exec: cat: not found
/usr/bin/google-chrome-stable: line 45: exec: cat: not found
uWSGI服务配置
[Unit]
Description=uWSGI instance to serve myproject
After=network.target
[Service]
User=myuser
Group=www-data
WorkingDirectory=/home/gbadmin/myproject
Environment="PATH=/home/gbadmin/myproject/myprojectenv/bin"
ExecStart=/home/gbadmin/myproject/myprojectenv/bin/uwsgi --ini myproject.ini
[Install]
WantedBy=multi-user.target
推荐答案
您为PATH
提供了太多限制:
Environment="PATH=/home/gbadmin/myproject/myprojectenv/bin"
有问题的命令通常出现在/bin
或/usr/bin
中,将它们添加到path变量中可能会解决您的问题
The missing commands in question are usually present in /bin
or /usr/bin
, adding these to the path variable will likely solve your problem
Environment="PATH=/home/gbadmin/myproject/myprojectenv/bin:/usr/bin:/bin"
这篇关于uWSGI python子进程chrome/firefox失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!