title: Problem deploying web.py script on IIS7 via PyISAPIe
body: <p>I have run into a problem while deploying a <a href="http://webpy.org/" rel="nofollow">web.py</a> single-file API on IIS 7 via <a href="http://www.google.com.pk/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CBYQFjAA&amp;url=http://pyisapie.sourceforge.net/&amp;ei=LZTLTYqpCcKDhQf1-oGpAg&amp;usg=AFQjCNF055NId0-sZVSpAuIJVmCTXGd1Zw" rel="nofollow">PyISAPIe</a>. I am going to talk about that today.</p>
  
  <p>I have successfully been able to deploy several Django web applications on IIS 7 using PyISAPIe. The <code>Isapi.py</code> module that I used for the Django sites looks similar to this:</p>
  
  <pre><code>from django.core.handlers.wsgi import WSGIHandler as DjangoHandler
  from Http.WSGI import RunWSGI
  from Http import 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)
  </code></pre>
  
  <p>However, not knowing how to tweak the above to use with my web.py script, I started with the <code>WSGI</code> example <code>Isapi.py</code> file. After additions, I have the following file:</p>
  
  <pre><code>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."
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>Thank you for your time.</p>
  
  <p><em>PS: I have this script, <code>device_api.py</code>, deployed under Apache2 using <code>mod_wsgi</code>, so I am certain there is nothing wrong with the code inside the script.</em></p>