0

I am trying to use Bottle.py and mod_wsgi together but I am getting a strange error that I cannot fix. When I try to make a curl request ("curl http://localhost/myapi/hello1") I get the error: "ImportError: No module named server". However, if I take out the "import server" line in my app.wsgi file and try "curl http://localhost/myapi/hello2" it works just fine. I have tried adding to the WSGIPythonPath, WSGIDaemonProcess, etc. and nothing has worked. Does anyone see anything I may be doing wrong?

Note: The "/usr/local/www/wsgi-script" path is successfully being added to sys.path, so that isn't the issue. I also do have a init.py file in the "/usr/local/www/wsgi-scripts" directory and the permissions are all 777.

[root@my_vm httpd]# ls -lt /usr/local/www/wsgi-scripts/
total 8
-rwxrwxrwx. 1 root root  95 Mar 21 14:42 server.py
-rwxrwxrwx. 1 root root 318 Mar 21 14:37 app.wsgi
-rwxrwxrwx. 1 root root   0 Mar 20 19:53 __init__.py

Using Versions:

Apache/2.4.6 (Red Hat Enterprise Linux)

Python 2.7.5

Bottle 0.12.9

/usr/local/www/wsgi-scripts/server.py

import bottle
from bottle import route

@route('/hello1')
def hello():
    return "Hello World!"

/usr/local/www/wsgi-scripts/app.wsgi

import os
import sys
import bottle
from bottle import route

server_loc = "/usr/local/www/wsgi-scripts"
if not server_loc in sys.path:
    sys.path.insert(0, server_loc)

os.chdir(os.path.dirname(__file__))

print(sys.path)

@route('/hello2')
def hello():
    return "Hello World!\n"

import server
application = bottle.default_app()

/etc/httpd/conf.d/myapi.conf

<VirtualHost *:80>
    ServerName localhost

    WSGIScriptAlias /myapi /usr/local/www/wsgi-scripts/app.wsgi

    <Directory /usr/local/www/wsgi-scripts>
        Require all granted
    </Directory>

</VirtualHost>

EDIT: Adding python traceback

/etc/httpd/logs/error_log

[Thu Mar 22 13:39:18.234573 2018] [core:notice] [pid 18172] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Thu Mar 22 13:39:29.628352 2018] [:error] [pid 18174] ['/usr/local/www/wsgi-scripts', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages']
[Thu Mar 22 13:39:29.628514 2018] [:error] [pid 18174] [client ::1:35838] mod_wsgi (pid=18174): Target WSGI script '/usr/local/www/wsgi-scripts/app.wsgi' cannot be loaded as Python module.
[Thu Mar 22 13:39:29.628525 2018] [:error] [pid 18174] [client ::1:35838] mod_wsgi (pid=18174): Exception occurred processing WSGI script '/usr/local/www/wsgi-scripts/app.wsgi'.
[Thu Mar 22 13:39:29.628539 2018] [:error] [pid 18174] [client ::1:35838] Traceback (most recent call last):
[Thu Mar 22 13:39:29.628556 2018] [:error] [pid 18174] [client ::1:35838]   File "/usr/local/www/wsgi-scripts/app.wsgi", line 18, in <module>
[Thu Mar 22 13:39:29.628625 2018] [:error] [pid 18174] [client ::1:35838]     import server
[Thu Mar 22 13:39:29.628645 2018] [:error] [pid 18174] [client ::1:35838] ImportError: No module named server
4
  • Can you provide the actual Python traceback and error? Commented Mar 21, 2018 at 22:38
  • @GrahamDumpleton Sure i'll update the post now Commented Mar 22, 2018 at 13:41
  • @GrahamDumpleton I just updated the post! I also tried deleting the init.py and same error. However, if I moved the server.py into another directory inside the directory (aka /usr/local/www/wsgi-scripts/server.py --> /usr/local/www/wsgi-scripts/inner_dir/server.py), and do "import inner_dir.server" instead of "import server", it starts working. Do you know why that may be? Commented Mar 22, 2018 at 13:48
  • I can't see anything obviously wrong. Since you should use mod_wsgi daemon mode anyway, maybe configure Apache to use that. modwsgi.readthedocs.io/en/develop/user-guides/… Commented Mar 22, 2018 at 21:22

1 Answer 1

0

Adding the solution that I found worked for me:

When I moved the server.py into another directory inside the directory (aka /usr/local/www/wsgi-scripts/server.py --> /usr/local/www/wsgi-scripts/inner_dir/server.py), and do "import inner_dir.server" instead of "import server", it started working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.