【发布时间】:2018-02-05 00:21:33
【问题描述】:
我在 uWSGI 下有一个使用 nginx 服务的 python 烧瓶应用程序。
python 代码调用subprocess.Popen() 来运行浏览器(即Firefox、Chrome),但uWSGI 日志显示错误。
该错误与linux(ubuntu)标准命令有关,即readlink、which、cat等。
我怀疑这与用户访问有关,但不确定。
uWSGI 服务使用我的用户和www-data 组运行。
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
【问题讨论】:
标签: python ubuntu nginx flask uwsgi