DashMachine icon indicating copy to clipboard operation
DashMachine copied to clipboard

Running via WSGI

Open Compizfox opened this issue 4 years ago • 1 comments

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:

  • I got the error Target WSGI script '/opt/DashMachine/wsgi.py' does not contain WSGI application 'application'. because WSGI expects an object named application. I fixed it by appending as application to line 12 in wsgi.py.

  • Running with WSGI, DashMachine crashes on the settings page whereas it runs fine with the development server. This is the traceback:

[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

Compizfox avatar Jun 07 '20 00:06 Compizfox

Same here, only difference is nginx.

Konradrundfunk avatar Jun 21 '20 14:06 Konradrundfunk