problem importing python module into wsgi file

#1
This returns a 500 error (doesn't work):

from pyadd.lib import addme
def application(environ, start_response):
q = environ['QUERY_STRING']
num1 = int(q[(q.index('=') + 1)])
num2 = int(q[(q.index('=',6) + 1)])
sum = str(addme(num1, num2))
start_response('200 OK', [('Content-Type', 'text/plain')])
return sum

This does work:

def application(environ, start_response):
q = environ['QUERY_STRING']
num1 = int(q[(q.index('=') + 1)])
num2 = int(q[(q.index('=',6) + 1)])
sum = str(num1 + num2)
start_response('200 OK', [('Content-Type', 'text/plain')])
return sum

This also works when run on the VPS independent of OLS:

from pyadd.lib import addme
q = "first=2&second=4"
num1 = int(q[(q.index('=') + 1)])
num2 = int(q[(q.index('=',6) + 1)])
sum = str(addme(num1, num2))
print(sum)

So it seems like there is no problem with the python (cffi) module itself adding the two numbers and returning an int and there is no problem getting the query string from OLS and there is no problem with the python code itself afaict. Does OLS not support importing modules into a WSGI file? I checked the PEP 3333 WSGI spec and it appears to be allowed. Is this a bug?
 
Last edited:

Pong

Administrator
#2
one of the command reason of 500 is the code issue. You may try the same code on your apache to see if it works or not.
 
#3
Well since it is just standard WSGI I could try to run it with any other WSGI compliant server. I guess that is the next logical troubleshooting step, but if it runs on the other server does that mean it's a bug with OLS? Believe it or not not only is Apache not installed on my VPS, but I have never used it.
 

Pong

Administrator
#4
many reasons could cause 500 error, If the python code itself work, it will pass on only one possibility. You can also check if there is any output in stderr log. https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:config:understanding_500

Another test you might consider is to add a simple test script there to see if python run ok with test script or not with OLS. If test script ok but your script 500, mostly something in the code triggerring the issue. https://openlitespeed.org/kb/python-wsgi-applications/
 
Top