rmountjoy92 / DashMachine

Another web application bookmark dashboard, with fun features.
GNU General Public License v3.0
1.24k stars 119 forks source link

Running via WSGI #179

Open Compizfox opened 4 years ago

Compizfox commented 4 years ago

Hi,

I wanted to run DashMachine using Apache with mod_wsgi. I could not find any specific instructions on how to do this (the README only describes how to run the development server), so I just tried it, since Flask should support it. However, it did not work immediately. These are the issues I encountered and what I had to do to fix it:

[2020-06-07 02:01:46,962] ERROR in app: Exception on /settings [GET]
Traceback (most recent call last):
  File "/opt/DashMachineEnv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/DashMachineEnv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/DashMachineEnv/lib/python3.8/site-packages/flask_restful/__init__.py", line 272, in error_router
    return original_handler(e)
  File "/opt/DashMachineEnv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/DashMachineEnv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/opt/DashMachineEnv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/DashMachineEnv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/DashMachine/dashmachine/settings_system/routes.py", line 42, in settings
    config.read(os.path.join(template_apps_folder, template_app_ini))
  File "/usr/lib/python3.8/configparser.py", line 697, in read
    self._read(fp, filename)
  File "/usr/lib/python3.8/configparser.py", line 1017, in _read
    for lineno, line in enumerate(fp, start=1):
  File "/usr/lib/python3.8/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 156: ordinal not in range(128)

This turned out to be a locale problem. Apparently Apache starts with LC_ALL=C, which breaks Unicode. This was fixed by appending lang=en_US.UTF-8 locale=en_US.UTF-8 to the WSGIDaemonProcess line in the Apache config.

FWIW, my Apache config ended up being:

WSGIDaemonProcess     dashmachine python-home=/opt/DashMachineEnv python-path=/opt/DashMachine/ lang=en_US.UTF-8 locale=en_US.UTF-8
WSGIProcessGroup      dashmachine
WSGIScriptAlias       /dashmachine /opt/DashMachine/wsgi.py
Konradrundfunk commented 4 years ago

Same here, only difference is nginx.