mod_wsgi中Adafruit_MotorHAT的权限被拒绝部署了Flask app

时间:2017-12-11 08:51:47

标签: python flask permissions raspberry-pi mod-wsgi

我正在开发一个简单的Flask应用程序,它由RaspberryPi提供,Adafruit MotorHat堆叠在它上面,因此它可以驱动步进电机。从命令行运行应用程序时,一切正常,可以通过Flask Web界面控制电机。但是,当尝试通过mod_wsgi部署应用程序时,我得到以下关于MotorHat库的apache2错误:

[Mon Dec 11 09:30:32.700209 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416] mod_wsgi (pid=1583): Target WSGI script '/var/www/FlaskApp  /flaskapp.wsgi' cannot be loaded as Python module.
[Mon Dec 11 09:30:32.700330 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416] mod_wsgi (pid=1583): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
[Mon Dec 11 09:30:32.700405 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416] Traceback (most recent call last):
[Mon Dec 11 09:30:32.700473 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]   File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>
[Mon Dec 11 09:30:32.700665 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]     from FlaskApp import app as application
[Mon Dec 11 09:30:32.700706 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 3, in <module>
[Mon Dec 11 09:30:32.700895 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]     from newsFocus import *
[Mon Dec 11 09:30:32.700933 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]   File "/var/www/FlaskApp/FlaskApp/newsFocus.py", line 14, in <module>
[Mon Dec 11 09:30:32.701313 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]     from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor, Adafruit_StepperMotor
[Mon Dec 11 09:30:32.701362 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]   File "build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/__init__.py", line 1, in <module>
[Mon Dec 11 09:30:32.701971 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]   File "build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/Adafruit_MotorHAT.py", line 3, in <module>
[Mon Dec 11 09:30:32.702522 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]   File "build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py", line 11, in <module>
[Mon Dec 11 09:30:32.703070 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]   File "build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py", line 35, in PWM
[Mon Dec 11 09:30:32.703619 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]   File "build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/Adafruit_I2C.py", line 43, in __init__
[Mon Dec 11 09:30:32.704127 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416]     self.bus = smbus.SMBus(busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber())
[Mon Dec 11 09:30:32.704204 2017] [wsgi:error] [pid 1583] [client 192.168.0.10:38416] IOError: [Errno 13] Permission denied

如何通过mod_wsgi解决此问题以及哪些用户实际运行应用程序?

1 个答案:

答案 0 :(得分:1)

用户Apache运行,因为没有权限访问您尝试访问的任何文件。参见:

虽然看起来不像这里的情况,但另一个常见问题是你使用相对路径名而不是绝对路径名。参见:

我建议您确保使用mod_wsgi的守护进程模式,并将守护程序进程的用户/组设置为任何用户有权访问您尝试访问的文件或设备。如果使用相对路径并且无法更改它们,请查看为进程设置主目录的选项。参见: