【问题标题】:Cant establish connection: HTSQL via mod_wsgi (file not found)无法建立连接:通过 mod_wsgi 的 HTSQL(未找到文件)
【发布时间】: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

我已经尝试过的事情:

  1. 复制错误直接在 Linux 上工作(目前在 MAMP 上工作)

  2. 直接通过python(cmd和xUbuntu终端)在托管在同一文件(htsql_demo.sqlite)上成功执行脚本 同一台服务器。

  3. 使用权限(将 777 设置为包含 htsql_demo.sqlite 的文件夹)

  4. 在 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.py os.getcwd() 不等于os.__file__。解决方案:a)Change work directory before open db b)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


【解决方案1】:

问题在于定义绝对路径。应该使用“%3A”而不是“:” 因此正确的路径是:

'sqlite:///C%3A/MAMP/Scripts/htsql_demo.sqlite'

【讨论】:

  • 你有两个 : 但是替换一个! import urllib; s = 'sqlite:///C:/MAMP/Scripts/htsql_demo.sqlite',输出为print urllib.quote(s)sqlite%3A///C%3A/MAMP/Scripts/htsql_demo.sqlite。此回复只会为您解决问题。
最近更新 更多