Error accessing a route endpoint with same name in 2 processes

27 views
Skip to first unread message

Νίκος Βέργος

unread,
Mar 7, 2020, 3:34:46 PM3/7/20
to modwsgi
Therere 2 different scripts each running on its own process:
www.py is what is running on http://superhost.gr
and test.py is what is running on http://superhost.gr/test
Here is what it contains.

from bottle import Bottle, route, run, debug
application = Bottle()
app = application
debug(True)

@app.route('/mailform', method=['POST'])
def mailform():
    return 'Hello from mailform'

@app.route('/')
def index():
    return '''\
    <form method="post" action="{}">
    <input value="Mail" type="submit" /> </form>'''.format( app.get_url( '/mailform' ) )

I somehow beleive that the following apache conf directives somehow create problem.

WSGIDaemonProcess test user=nikos group=nikos home=/home/nikos/wsgiWSGIScriptAlias /test /home/nikos/wsgi/test.py process-group=test application-group=%{GLOBAL}
WSGIDaemonProcess www user=nikos group=nikos home=/home/nikos/wsgiWSGIScriptAliasMatch / /home/nikos/wsgi/www.py process-group=www application-group=%{GLOBAL}

The only way i can run this is the aforementioned.
IF instead i try to access the endpoint like the following:

@app.route('/')
    def index(): return '''\
    <form method="post" action="/mailform">
    <input value="Mail" type="submit" /> </form>'''

i receive:
Sorry, the requested URL 'http://superhost.gr/mailform' caused an error:
Internal Server ErrorException:
TypeError("argument of type 'NoneType' is not iterable",)Traceback:Traceback (most recent call last): File "/home/nikos/wsgi/bottle.py", line 996, in _handle out = route.call(**args) File "/home/nikos/wsgi/bottle.py", line 2007, in wrapper rv = callback(*a, **ka) File "/home/nikos/wsgi/www.py", line 189, in mailform if provider in FROM:TypeError: argument of type 'NoneType' is not iterable

I somehow beleive that the following apache conf directives somehow create problem.
You will see if you create a route endpoint called '/mailform' within '/' which is an alias of 'www.py' and you also have '/mailform' in 'superhost.gr/test' when the latter tries to post data to '/mailform' instead of sending them to 'superhost.gr/test/' it sends them to '/' which is 'superhost.gr'

Graham Dumpleton

unread,
Mar 7, 2020, 3:56:39 PM3/7/20
to mod...@googlegroups.com
If you add debug statements to index(), what is the value of:

    request.environ.get('SCRIPT_NAME')

for the request?

Also add an import to the top of the script for the module 'mod_wsgi', and print the value of:

    mod_wsgi.process_group()

for the request.

Finally, look at the source code for the HTML coming back to your browser. What is the complete filled out form as seen by the browser.

What you should see for SCRIPT_NAME for original test.py is:

    /test

For the process group you should see:

    test

and in the form, the action should be:

    /test/mailform

When you hardwire action to '/mailform', because it lacks the '/test' prefix which is the mount point for the application, it will send to the www application mounted at '/' instead as it will not have the '/test' prefix.

So because you mounted application at a sub URL path, it is important that you use app.get_url() when generating all URLs so that the framework can add the mount point URL specified by SCRIPT_NAME to the start of all URLs.

Anyway, hope that helps as I wasn't 100% clear with what you were describing as the problem.

BTW, you really should avoid using WSGIScriptAliasMatch. There is usually never a need to and it can be tricky to use when trying to actually match a pattern as you need to give a hint as to the mount point to pass to the application. In this case you could have just used:

WSGIDaemonProcess test user=nikos group=nikos home=/home/nikos/wsgi
WSGIScriptAlias /test /home/nikos/wsgi/test.py process-group=test application-group=%{GLOBAL}
WSGIDaemonProcess www user=nikos group=nikos home=/home/nikos/wsgi
WSGIScriptAlias / /home/nikos/wsgi/www.py process-group=www application-group=%{GLOBAL}

There was no need to use WSGIScriptAliasMatch.

FWIW, you can see rules about URL reconstruction when needing to supply a URL in a response at:


This is in part what the app.get_url() function is doing.

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/706267e7-b7b4-4991-b635-6d9f3e1ba52a%40googlegroups.com.

Νίκος

unread,
Mar 7, 2020, 4:16:32 PM3/7/20
to mod...@googlegroups.com

Thank you very much Graham for the detailed explanation!

 

Sent from Mail for Windows 10

Νίκος Βέργος

unread,
Mar 7, 2020, 4:25:05 PM3/7/20
to modwsgi
I also wanted to ask you this:

I'am using Apache + mod_wsgi to create web apps.

Do you think it would be better, perhaps faster and more secure - if i start using Apache + gunicorn as wsgi wrapper OR nginx + gunicorn OR some other combination OR i should start with my current configuration?!

Graham Dumpleton

unread,
Mar 7, 2020, 4:29:45 PM3/7/20
to mod...@googlegroups.com
If you are only just starting out, performance should be the least of your concerns. All the WSGI servers will perform fine for the bulk of things people do. You are better off focusing on the functionality of your application. So stick for Apache/mod_wsgi for now, its integrated approach is going to be safer. There is no need to complicate things for yourself by adding more moving parts.

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.

Νίκος Βέργος

unread,
Mar 7, 2020, 4:34:13 PM3/7/20
to mod...@googlegroups.com

 Thank you for the insight Graham, i'll stick to Apache/mod_wsgi

 

Sent from Mail for Windows 10

 

From: Graham Dumpleton
Sent: Σάββατο, 7 Μαρτίου 2020 11:29 μμ
To:
mod...@googlegroups.com
Subject: Re: [modwsgi] Error accessing a route endpoint with same name in 2 processes

 

If you are only just starting out, performance should be the least of your concerns. All the WSGI servers will perform fine for the bulk of things people do. You are better off focusing on the functionality of your application. So stick for Apache/mod_wsgi for now, its integrated approach is going to be safer. There is no need to complicate things for yourself by adding more moving parts.

Reply all
Reply to author
Forward
0 new messages