Python 无法通过mod_wsgi建立连接:HTSQL(未找到文件)
我想使用mod_wsgi在apache服务器上集成HTSQL。 apache和mod_wsgi都已成功配置,hello world python脚本执行并工作强> 然而,当我尝试运行htsqlpython脚本(名为HTSQL_wsgi.py并使用以下指令:)时,我得到一个500内部服务器错误。你能给我一个解决方案吗 Apache错误日志显示:Python 无法通过mod_wsgi建立连接:HTSQL(未找到文件),python,apache,mamp,mod-wsgi,htsql,Python,Apache,Mamp,Mod Wsgi,Htsql,我想使用mod_wsgi在apache服务器上集成HTSQL。 apache和mod_wsgi都已成功配置,hello world python脚本执行并工作 然而,当我尝试运行htsqlpython脚本(名为HTSQL_wsgi.py并使用以下指令:)时,我得到一个500内部服务器错误。你能给我一个解决方案吗 Apache错误日志显示: [Wed Apr 13 16:26:29 2016] [error] [client 127.0.0.1] mod_wsgi (pid=5760): Targ
[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
[Wed Apr 13 16:26:29 2016][error][client 127.0.0.1]mod_wsgi(pid=5760):无法将目标wsgi脚本'C:/MAMP/scripts/htsql_wsgi.py'作为Python模块加载。
[Wed Apr 13 16:26:29 2016][error][client 127.0.0.1]mod_wsgi(pid=5760):处理wsgi脚本“C:/MAMP/scripts/htsql_wsgi.py”时发生异常。
[2016年4月13日星期三16:26:29][error][client 127.0.0.1]回溯(最近一次通话):
[Wed Apr 13 16:26:29 2016][error][client 127.0.0.1]文件“C:/MAMP/scripts/htsql_wsgi.py”,第8行,在
[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]文件“C:\\MAMP\\bin\\python\\lib\\site packages\\htsql\\core\\application.py”,第186行,在__
[2016年4月13日星期三16:26:29][error][client 127.0.0.1](addon.name,exc))
[Wed Apr 13 16:26:29 2016][error][client 127.0.0.1]导入错误:未能初始化“htsql”:未能建立数据库连接:文件不存在:htsql\u demo.sqlite
我已经尝试过的事情:
非常感谢您的建议问题在于定义绝对路径。而不是“:”应使用“%3A” 因此,正确的路径是:
'sqlite:///C%3A/MAMP/Scripts/htsql_demo.sqlite'
问题在于定义绝对路径。而不是“:”应使用“%3A” 因此,正确的路径是:
'sqlite:///C%3A/MAMP/Scripts/htsql_demo.sqlite'
数据库文件的路径名是什么?您不应该使用相对路径名,因为进程的当前工作目录不在代码所在的位置。尝试了几种不同的路径,如sqlite:///C:\MAMP\Scripts\htsql\u demo.sqlite;sqlite:C:\MAMP\Scripts\htsql\u demo.sqlite;sqlite://C:/MAMP/Scripts/htsql\u demo.sqlite;诸如此类。。。你知道什么应该是正确的吗?试试“sqlite:///C:/MAMP/Scripts/htsql_demo.sqlite". 在Python中,不要对Windows上的路径在字符串中使用反斜杠,因为反斜杠将被解释为转义以下字符。在运行
htsql\u wsgi.py
os.getcwd()
后,反斜杠不等于os.\uu文件\uu
。解决方案:a)在打开db之前更改工作目录
b)给出完整路径(仅文件名不工作)
c)Apache不允许外部文件(如果不确定权限,httpuser无法访问外部文件)
@Graham:您的解决方案不起作用,以前已尝试过。数据库文件的路径名是什么?您不应该使用相对路径名,因为进程的当前工作目录不在代码所在的位置。尝试了几种不同的路径,如sqlite:///C:\MAMP\Scripts\htsql\u demo.sqlite;sqlite:C:\MAMP\Scripts\htsql\u demo.sqlite;sqlite://C:/MAMP/Scripts/htsql\u demo.sqlite;诸如此类。。。你知道什么应该是正确的吗?试试“sqlite:///C:/MAMP/Scripts/htsql_demo.sqlite". 在Python中,不要对Windows上的路径在字符串中使用反斜杠,因为反斜杠将被解释为转义以下字符。在运行htsql\u wsgi.py
os.getcwd()
后,反斜杠不等于os.\uu文件\uu
。解决方案:a)在打开db之前更改工作目录
b)提供完整路径(仅文件名不工作)
c)Apache不允许外部文件(如果不确定权限,httpuser无法访问外部文件)
@Graham:您的解决方案不起作用,以前已经尝试过了。您有两个:
,但替换一个<代码>导入urllib;s=sqlite:///C:/MAMP/Scripts/htsql_demo.sqlite“,输出为print urlib.quote
sqlite%3A///C%3A/MAMP/Scripts/htsql\u demo.sqlite
。此答复只为您解决了一个问题。您有两个:
,但要替换一个<代码>导入urllib;s=sqlite:///C:/MAMP/Scripts/htsql_demo.sqlite“,输出为print urlib.quote
sqlite%3A///C%3A/MAMP/Scripts/htsql\u demo.sqlite
。这个答复只为您解决了一个问题。