【发布时间】:2024-01-05 15:45:01
【问题描述】:
我想在 apache 服务器上使用 mod_wsgi 集成 HTSQL强>。 apache 和 mod_wsgi 均已成功配置,hello world python 脚本执行并运行!
但是,当我尝试运行 HTSQL python 脚本(名为 htsql_wsgi.py 并使用以下说明:http://htsql.org/doc/admin/deploy.html)时,我收到 500 内部服务器错误。你能给我一个解决方案吗?
Apache 错误日志显示:
[Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] mod_wsgi (pid=5760): Target WSGI script 'C:/MAMP/scripts/htsql_wsgi.py' cannot be loaded as Python module.
[Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] mod_wsgi (pid=5760): Exception occurred processing WSGI script 'C:/MAMP/scripts/htsql_wsgi.py'.
[Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] File "C:/MAMP/scripts/htsql_wsgi.py", line 8, in <module>
[Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] application = HTSQL(DB)
[Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] File "C:\\MAMP\\bin\\python\\lib\\site-packages\\htsql\\core\\application.py", line 186, in __init__
[Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] % (addon.name, exc))
[Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] ImportError: failed to initialize 'htsql': failed to establish database connection: file does not exist: htsql_demo.sqlite
我已经尝试过的事情:
-
复制错误直接在 Linux 上工作(目前在 MAMP 上工作)
-
直接通过python(cmd和xUbuntu终端)在托管在同一文件(htsql_demo.sqlite)上成功执行脚本 同一台服务器。
-
使用权限(将 777 设置为包含 htsql_demo.sqlite 的文件夹)
-
在 httpd.conf 上使用权限(使用目录、文件、位置更改设置)
使用 MAMP(Windows 7、Apache 2.2.、Python 2.7.)或 xUbuntu(Apache 2.4.、Python 2.7.)时会出现问题。在两台机器上,错误都是一样的。
非常感谢您的建议
【问题讨论】:
-
您为数据库文件使用的路径名是什么?您不应该使用相对路径名,因为进程的当前工作目录不会是您的代码所在的位置。
-
尝试了几种不同的路径,例如 sqlite:///C:\MAMP\Scripts\htsql_demo.sqlite; sqlite:C:\MAMP\Scripts\htsql_demo.sqlite; sqlite://C:/MAMP/Scripts/htsql_demo.sqlite;等等等等……你知道什么应该是正确的吗?
-
尝试使用“sqlite:///C:/MAMP/Scripts/htsql_demo.sqlite”。不要在 Python 中的字符串中对 Windows 上的路径使用反斜杠,因为反斜杠将被解释为转义以下字符。
-
运行后
htsql_wsgi.pyos.getcwd()不等于os.__file__。解决方案:a)Change work directory before open dbb)give full path(don't work only filename)c)Apache don't allow external file(httpuser can't acces external files if don't determine permission ) -
@Graham:您的解决方案不起作用,之前已经尝试过。
标签: python apache mamp mod-wsgi htsql