Problem deploying web.py script on IIS7 via PyISAPIe
I have run into a problem while deploying a web.py single-file API on IIS 7 via PyISAPIe. I am going to talk about that today.
I have successfully been able to deploy several Django web applications on IIS 7 using PyISAPIe. The Isapi.py
module that I used for the Django sites looks similar to this:
from django.core.handlers.wsgi import WSGIHandler as DjangoHandler
from Http.WSGI import RunWSGI
from Http i开发者_C百科mport Env
import os
import sys
sys.path.append(r"C:\projects\myproject")
os.environ["DJANGO_SETTINGS_MODULE"] = "myproject.settings"
Base = "/"
Exclude = ["/media"]
Handler = DjangoHandler()
def Request():
PathInfo = Env.PATH_INFO
return RunWSGI(Handler, Base=Base)
However, not knowing how to tweak the above to use with my web.py script, I started with the WSGI
example Isapi.py
file. After additions, I have the following file:
from Http.WSGI import RunWSGI
from Http import Env
from md5 import md5
import imp
import os
import sys
sys.path.append(r"C:\projects\otherproject\")
SCRIPT_PATH = 'C:\projects\otherproject\device_api.py'
ScriptHandlers = {
"/": r"C:\projects\otherproject\device_api.py",
}
def RunScript(Path):
global ScriptHandlers
try:
return ScriptHandlers[Path]()
except KeyError:
Name = '__'+md5(Path).hexdigest().upper()
ScriptHandlers[Path] = \
imp.load_source(Name, Env.SCRIPT_TRANSLATED).Request
return ScriptHandlers[Path]()
Apps = {
# "/app/django/" : lambda P: RunWSGI(DjangoHandler()),
# "/app/trac/" : lambda P: RunWSGI(TracHandler),
"/" : lambda P: RunScript(P),
}
def Request():
Name = Env.SCRIPT_NAME
for App, Handler in Apps.items():
if Name.startswith(App):
return Handler(Name)
raise Exception, "Handler not found."
I am sure that there is something that I am overlooking or plainly doing wrong. When I try to access the script on the browser, I get a 500 response from IIS with the following details:
Could not initialize interpreter
Traceback (most recent call last):
File "C:\projects\pyisapie\Http\Isapi.py", line 29, in
from md5 import md5
File "C:\Python26\Lib\md5.py", line 8, in
DeprecationWarning, 2)
File "C:\Python26\Lib\warnings.py", line 29, in _show_warning
file.write(formatwarning(message, category, filename, lineno, line))
Exception: Not currently processing a request
While I am still playing around with different tweaks and such, I am not exactly sure what I need to do to get it working. Any help in that direction will be really greatly appreciated.
Thank you for your time.
PS: I have this script, device_api.py
, deployed under Apache2 using mod_wsgi
, so I am certain there is nothing wrong with the code inside the script.
After labouring for days, I finally found a solution. I wrote it down in detail. I am going to provide a link to my blog post where I have put it down. It's titled, "Guide: Deploying web.py on IIS7 using PyISAPIe". I hope it helps someone facing similar issues.
Thank you.
精彩评论