1

I would like to integrate HTSQL on apache server using mod_wsgi. Both apache and mod_wsgi were successfully configured, hello world python script executes and works!

However, when I try to run HTSQL python script (named htsql_wsgi.py and using these instructions: http://htsql.org/doc/admin/deploy.html), I get a 500 Internal Server Error. Can you suggest me a solution?

Apache error log shows:

[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

Things I've already tried:

  1. Replicate error working directly on Linux (currently working on MAMP)

  2. Successfully execute script directly via python (both cmd and xUbuntu terminal) on the same file (htsql_demo.sqlite) hosted on the same server.

  3. Play with the permissions (set 777 to folder containing htsql_demo.sqlite)

  4. Play with permissions on httpd.conf (changing settings using directory, files, locations)

Problem occurs using MAMP (Windows 7, Apache 2.2., Python 2.7.) or xUbuntu (Apache 2.4., Python 2.7.). On both machines, the error is the same.

Many thanks for your suggestions

Community
  • 1
  • 1
Dfinzgar
  • 88
  • 5
  • What is the path name you are using for the database file? You should not use a relative path name as the current working directory of the process isn't going to be where your code is. – Graham Dumpleton Apr 19 '16 at 09:19
  • Tried several different paths like sqlite:///C:\MAMP\Scripts\htsql_demo.sqlite; sqlite:C:\MAMP\Scripts\htsql_demo.sqlite; sqlite://C:/MAMP/Scripts/htsql_demo.sqlite; and so on and so forth... Do you know what should be the correct one? – Dfinzgar Apr 19 '16 at 12:54
  • Try with "sqlite:///C:/MAMP/Scripts/htsql_demo.sqlite". Don't use backslashes in strings in Python for paths on Windows as the backslash will be interpreted as escaping the following character. – Graham Dumpleton Apr 19 '16 at 22:20
  • After run `htsql_wsgi.py` `os.getcwd()` not equal to `os.__file__`. Solution : 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 )` – dsgdfg Apr 20 '16 at 15:48
  • @Graham: your solution doesnt work, tried it already before. – Dfinzgar Apr 20 '16 at 21:08
  • @dsgdfg: solution b) does not work. solution c) permissions are not the case, already tried that. Solution a) change it to what? To where the database file is? Isnt that risky? – Dfinzgar Apr 20 '16 at 21:10

1 Answers1

0

The problem was with defining the absolute path. Instead of ":" one should use "%3A" therefore the correct path would be:

'sqlite:///C%3A/MAMP/Scripts/htsql_demo.sqlite'
Dfinzgar
  • 88
  • 5
  • You got two `:` but replace one ! `import urllib; s = 'sqlite:///C:/MAMP/Scripts/htsql_demo.sqlite'`, output is `print urllib.quote(s)` `sqlite%3A///C%3A/MAMP/Scripts/htsql_demo.sqlite`. This reply only fixes a problem for you. – dsgdfg Apr 22 '16 at 06:59