Question

I am a beginner programmer. I started using Python and Bottle for a small web app to print a form, so far so good. The real issue is configuring Apache and mod_wsgi, as my knowledge is almost none.

My problem: I keep getting this error:

Error 404: Not Found

Sorry, the requested URL /factura/ caused an error: Not found

In work they gave me and address redirecting to a IP:port; after some days of reading Apache docs and looking examples through the web I managed to set up the configuration so my VirtualHost doesn't breaks the others virtualhosts already running. The config looks like this (based on the bottle tutorial deployment section):

Listen port
NameVirtualHost IP:port

<VirtualHost IP:port>
    ServerName IP:port

    WSGIDaemonProcess factura processes=1 threads=5
    WSGIScriptAlias / /var/www/factura/app.wsgi

    <Directory /var/www/factura>
        WSGIProcessGroup factura
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

My app.wsgi is almost the same as the one in the Bottle tutorial-deployment section. I only added the line sys.stdout = sys.stderr:

import sys, os, bottle

# Change working directory so relative paths (and template lookup) work again
sys.path = ['/var/www/factura'] + sys.path
os.chdir(os.path.dirname(__file__))

# Error output redirect
# Exception KeyError in 'threading' module
sys.stdout =  sys.stderr

import factura
application = bottle.default_app()

Here is a bit of the python code which is related to Bottle:

from lib import bottle

app = bottle.Bottle()

#serves files in folder 'static'
@app.route('/static/:path#.+#', name='static')
def ...

@app.route("/factura")
@bottle.view("factura")
def ...

@app.route("/print_factura", method="POST")
def ...

I have read some of the others question similar to this, but I can't manage to see what I'mm missing. I suppose the problem is in app.wsgi?

UPDATE

file structure

/var/www/factura/       ## .py files
                /views  ## here is the web template
                /static ## .css and .js of template
                /lib    ## package with bottle and peewee source files
                /data   ## inkscape file to play with
                /bin    ## backup stuff in repo, not used in code

Apache error log only shows

Exception KeyError: KeyError(-1211426160,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored that is a warning from wsgi/python issues, harmless by wsgi issue 197

UPDATE 2 working
added @app.route("/factura/") notice the trail slash, that with the change in app import from factura import app as application those two together made it work

Was it helpful?

Solution

If you create your application explicitly:

app = bottle.Bottle()

then you should import it in your app.wsgi instead of application = bottle.default_app():

from factura import app as application

But what is far important is this. In your WSGI file, you do import bottle, yet in the app code file, you do from lib import bottle. As you have explained, you have two copies of Bottle: one installed server-wide, another under the lib directory.

That's why you were receiving 404 Not Found. You were actually working with one instance of the library (creating app), and then giving Apache a different (default_app) from a different instance of the library!

It started to work okay when you began to return the proper app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top