I have a test script, test_wsgi.py. See below. This is working. I can hit https://opencalaccess.org/test_wsgi and I get a good result, so I think that mod_wsgi is properly set up.
But when I access my main script, I get a 500.
Here is the bit in my conf:
WSGIScriptAlias /test_wsgi /var/www/opencalaccess_org/test_script.py
WSGIDaemonProcess opencalaccess_org threads=5 python-home=/var/www/opencalaccess_org/contracts_scc/.venv
WSGIScriptAlias /data /var/www/opencalaccess_org/contracts_scc/app.py
<Directory /var/www/opencalaccess_org/contracts_scc/>
WSGIProcessGroup opencalaccess_org
WSGIApplicationGroup %(GLOBAL)
Require all granted
</Directory>
My app has:
activate_this = '/var/www/opencalaccess_org/contracts_scc/.venv/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import re
from jinja2 import Environment, PackageLoader
from flask import Flask
from flask import request
import data
app = Flask(__name__)
env = Environment(loader=PackageLoader('app', 'pages'))
# env = Environment(bytecode_cache=MyCache(), loader=PackageLoader('app', 'pages'))
@app.route('/')
def hello_world():
return '<h2><a href="contracts/scc">Launch</a></h2>'
Now I see something in the error.log:
[wsgi:info] [pid 229274] mod_wsgi (pid=229274, process='opencalaccess_org', application='%(GLOBAL)'): Loading Python script file '/var/www/opencalaccess_org/contracts_scc/app.py'.
[wsgi:error] [pid 229274] mod_wsgi (pid=229274): Failed to exec Python script file '/var/www/opencalaccess_org/contracts_scc/app.py'.
[wsgi:error] [pid 229274] mod_wsgi (pid=229274): Exception occurred processing WSGI script '/var/www/opencalaccess_org/contracts_scc/app.py'.
[wsgi:error] [pid 229274] Traceback (most recent call last):
[wsgi:error] [pid 229274] File "/var/www/opencalaccess_org/contracts_scc/app.py", line 7, in <module>
[wsgi:error] [pid 229274] import jinja2
[wsgi:error] [pid 229274] File "/var/www/opencalaccess_org/contracts_scc/.venv/lib/python3.8/site-packages/jinja2/__init__.py", line 5, in <module>
[wsgi:error] [pid 229274] from .bccache import BytecodeCache as BytecodeCache
[wsgi:error] [pid 229274] File "/var/www/opencalaccess_org/contracts_scc/.venv/lib/python3.8/site-packages/jinja2/bccache.py", line 26
[wsgi:error] [pid 229274] def get(self, key: str) -> bytes:
[wsgi:error] [pid 229274] ^
[wsgi:error] [pid 229274] SyntaxError: invalid syntax
I can run my app manually, accessing it via a hard-coded port, using the same .venv that the conf file is pointing to.
By the way, from my pip freeze:
click==8.1.3
Flask==2.2.2
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
Werkzeug==2.2.2
cat test_wsgi.py:
def application(environ,start_response):
status = '200 OK'
html = '\n' \
'\n' \
' mod_wsgi is working\n' \
'\n' \
'\n'
response_header = [('Content-type','text/html')]
start_response(status,response_header)
return [html]
Now I have:
- renamed app.py to contract_scc.py
- changed the WSGIDaemonProcess line to:
WSGIDaemonProcess contracts_scc threads=5 user=ray python-home=/var/www/opencalaccess_org/contracts_scc/.venv
- changed my routes in my contracts_scc.py to:
contracts_scc = Flask(name)
env = Environment(loader=PackageLoader('contracts_scc', 'pages'))
@contracts_scc.route('/')
def hello_world():
return '<h2><a href="contracts/scc">Launch</a></h2>'
Now, I am seeing, in the error.log:
either:
[] Traceback (most recent call last):
[] File "/var/www/opencalaccess_org/contracts_scc/contracts_scc.py", line 10, in <module>
[] import data
or
Target WSGI script '/var/www/opencalaccess_org/contracts_scc/contracts_scc.py' does not contain WSGI application 'application'.
What the f? –