1

I created a flask application which runs a selenium script. Within flask it works just fine, however when I transfer it to apache using wsgi I get this error from the apache.log. The templates load but the selenium script doesn't run. I will attach the relevant error.log lines as well as the config files. Any help will be greatly appreciated!

[Sun Nov 20 00:37:28.995529 2016] [wsgi:error] [pid 7492:tid 1954542640]   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/service.py", line 45, in __init__
[Sun Nov 20 00:37:28.995545 2016] [wsgi:error] [pid 7492:tid 1954542640]     log_file = open(log_path, "a+")
[Sun Nov 20 00:37:28.995560 2016] [wsgi:error] [pid 7492:tid 1954542640] IOError: [Errno 13] Permission denied: 'geckodriver.log'

webroombooker.config

<VirtualHost *:80>
            ServerName localhost

            WSGIScriptAlias / /home/pi/Website/webroombooker.wsgi

            <Directory /home/pi/Website/>
                    Require all granted
            </Directory>

            ErrorLog ${APACHE_LOG_DIR}/error.log
            LogLevel warn
            CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

000-default.config

<Directory /home/pi/Website/>
            Require all granted
</Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

webroombooker.wsgi

#!/usr/bin/python

import sys
import logging

logging.basicConfig(stream=sys.stderr)

sys.path.insert(0,"/home/pi/Website")

from webroombooker import app as application

Thank you in advanced! I'm pretty new to this!

Jack Gruber
  • 47
  • 1
  • 7
  • 1
    Apache runs as differrent user, in different environment, and with different privileges. Mostly it runs as user `www-data` so this user needs access to your files. – furas Nov 20 '16 at 06:10
  • I used chmod 777 on the file and question and still got the same result – Jack Gruber Nov 20 '16 at 06:19
  • and what mode do you use on folder (and its parent folders) ? – furas Nov 20 '16 at 06:24
  • the folder the log file inside has also had chmod 777 used on it. my home folder's permissions aren't as loose though. Is this the problem? – Jack Gruber Nov 20 '16 at 06:32
  • other user can access your files only if it has access to all folders on path `/full/path/with/many/folders/geckodriver.log` - or use `/var/log` folder. – furas Nov 20 '16 at 06:36
  • All the permissions are set correctly in all of the folders I'm pretty sure. – Jack Gruber Nov 20 '16 at 06:56

1 Answers1

0

The current working directory of your WSGI application process under Apache/mod_wsgi will generally be the root directory. That directory is owned by the root user. Because you are trying to use a relative path name to the log file, rather than absolute, it will try and write the directory to the root directory, which because it is owned by the root user, you can't do. See:

For logging when running under Apache/mod_wsgi, you are better off configuring the application to log to stderr. That way it is captured in the Apache error log and you do not have to be concerned about where you can write a log file.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • Thank you! The problem is that selenium by default logs to this file. I don't think there is a way to stop this. – Jack Gruber Nov 20 '16 at 06:55
  • Do you create the Firefox driver in your code. If you do, try passing ``browser = webdriver.Firefox(log_path=None)``, or pass an absolute log file path for a location that the user Apache runs as can write to. See similar thing for other drivers mentioned in http://blog.michaelyin.info/2015/05/18/how-to-disable-ghostdriver-log-when-using-selenium/ If you look at code for Selenium, the Firefox driver uses different param name to that drives mentioned in blog post. – Graham Dumpleton Nov 20 '16 at 07:35
  • I didn't create it. It just creates it automatically. log_path=None didn't work too well. Thanks though! – Jack Gruber Nov 20 '16 at 15:21