python - Invalid Syntax class Template(metaclass=_TemplateMetaclass) with mod_wsgi, apache and sqlalchemy -
i have script import:
from bottle import route, request sqlalchemy import create_engine, metadata sqlalchemy.ext.declarative import declarative_base sqlalchemy.orm import sessionmaker sqlalchemy import table, column, integer import xml.etree.celementtree et @route('/getmember') def get_member(): pass run(host='localhost', port=8080, reloader=true)
i can run script using bottle build in web server: $python3.2 getmember.py
that done want run app using apache , mod_wsgi
, create script called adapter.wsgi
:
import sys, os, bottle sys.path = ['/var/www/getmember/'] + sys.path os.chdir(os.path.dirname(__file__)) import getmember application = bottle.default_app()
in apache have:
wsgidaemonprocess getmember user=www-data group=www-data processes=1 threads=5 python-path=/usr/lib/python3.2/site-packages wsgiscriptalias /getmember /var/www/idcheck/adapter.wsgi <directory /var/www/getmember> wsgiprocessgroup getmember wsgiapplicationgroup %{global} order deny,allow allow </directory>
when run script using browser on: localhost/getmember
, http 200 error , apache error log shows:
mod_wsgi (pid=10271): exception occurred processing wsgi script '/var/www/getmember/adapter.wsgi'. traceback (most recent call last): file "/var/www/getmember/adapter.wsgi", line 7, in <module> import getmember # loads application file "/var/www/getmember/getmember.py", line 10, in <module> sqlalchemy import create_engine, metadata file "/usr/lib/python3.2/site-packages/sqlalchemy-0.8.0b2-py3.2.egg/sqlalchemy/__init__.py", line 10, in <module> .sql import ( file "/usr/lib/python3.2/site-packages/sqlalchemy-0.8.0b2-py3.2.egg/sqlalchemy/sql/__init__.py", line 7, in <module> .expression import ( file "/usr/lib/python3.2/site-packages/sqlalchemy-0.8.0b2-py3.2.egg/sqlalchemy/sql/expression.py", line 34, in <module> .. import util, exc, inspection file "/usr/lib/python3.2/site-packages/sqlalchemy-0.8.0b2-py3.2.egg/sqlalchemy/util/__init__.py", line 7, in <module> .compat import callable, cmp, reduce, defaultdict, py25_dict, \\ file "/usr/lib/python3.2/site-packages/sqlalchemy-0.8.0b2-py3.2.egg/sqlalchemy/util/compat.py", line 100, in <module> urllib.parse import parse_qsl importerror: no module named parse
so why working under normal python call (meaning libraries , packages okay) yet under wsgi & apache throws error? feeling cannot find requried path package not sure how add it.
edit
i ran import sys
, print sys.path
paths loaded when run python3.2 environment. got multiple paths added python-path in apache:
wsgidaemonprocess idcheck user=www-data group=www-data processes=1 threads=5 python-path=/usr/local/lib/python3.2/dist-packages/distribute-0.6.34-py3.2.egg:/usr/local/lib/python3.2/dist-packages/logilab_common-0.58.3-py3.2.egg:/usr/local/lib/python3.2/dist-packages/logilab_astng-0.24.1-py3.2.egg:/usr/local/lib/python3.2/dist-packages/sqlalchemy-0.8.0b2-py3.2.egg:/usr/local/lib/python3.2/dist-packages/psycopg2-2.4.6-py3.2-linux-x86_64.egg:/usr/local/lib/python3.2/dist-packages/pip-1.2.1-py3.2.egg:/usr/local/lib/python3.2/dist-packages/sqlautocode-0.6b1-py3.2.egg:/usr/lib/python3.2:/usr/lib/python3.2/plat-linux2:/usr/lib/python3.2/lib-dynload:/usr/local/lib/python3.2/dist-packages:/usr/lib/python3/dist-packages
with that, earlier error disappeared , got new 1 of invalid syntax. there broken sqlalchemy , mod_wsgi + apache?
mod_wsgi (pid=21339): target wsgi script '/var/www/getmember/adapter.wsgi' cannot loaded python module. mod_wsgi (pid=21339): exception occurred processing wsgi script '/var/www/getmember/adapter.wsgi'. traceback (most recent call last): file "/var/www/getmember/adapter.wsgi", line 6, in <module> import getmember # loads application file "/var/www/getmember/getmember.py", line 10, in <module> sqlalchemy import create_engine, metadata file "/usr/local/lib/python3.2/dist-packages/sqlalchemy-0.8.0b2-py3.2.egg/sqlalchemy/__init__.py", line 7, in <module> import inspect _inspect file "/usr/lib/python3.2/inspect.py", line 36, in <module> import string file "/usr/lib/python3.2/string.py", line 89 class template(metaclass=_templatemetaclass): ^ syntaxerror: invalid syntax
perhaps apache using version 2 python executable? check search path of apache user or @ wsgi directives wsgipythonhome / wsgipythonexecutable.
try:
import sys
-snip-
@route('/test', method='get') def test(): return sys.version
or:
#grep python /var/log/httpd/error_log
Comments
Post a Comment