CherryPy3 and IIS 6.0

I have a small Python web application using the Cherrypy environment. I am by no means a specialist in web servers.

I got Cherrypy working with Apache using mod_python on our Ubuntu server. However, this time I have to use Windows 2003 and IIS 6.0 to host my site.

The site works great as a standalone server - I'm just lost when it comes to running IIS. I spent the last day of Googling and blindly tried everything and everything to achieve this.

I have all the various tools installed for websites (Python 2.6, CherrpyPy 3, ISAPI-WSGI, PyWin32), and I read all the documentation. This blog was most helpful:

http://whatschrisdoing.com/blog/2008/07/10/turbogears-isapi-wsgi-iis/

But I'm still losing what I need to run my site. I can’t even find any detailed examples or practical tips. I hope someone here can help!

Greetings.

+4
source share
2 answers

Ok, I started to work. Thanks to Jason and all his help. I needed to call

cherrypy.config.update({ 'tools.sessions.on': True }) return cherrypy.tree.mount(Root(), '/', config=path_to_config) 

I had it in the configuration file in the [/] section, but for some reason he did not like it. Now I can start and run my web application - then I think I will try to understand why he needs this update, and I don’t like the configuration file that I have ...

+2
source

I am running CherryPy for my IIS sites. There are several tricks to make it work.

  • When working as an IIS workflow identifier, you will not have the same permissions as when starting a site from a user process. Everything will break. In particular, everything that it wants to write to the file system will probably not work without any configuration.
  • If you use setuptools, you probably want to install your components with the -Z option (unpacks all eggs).
  • Use win32traceutil to troubleshoot. Make sure on your hook script that you are importing win32traceutil. Then, when you try to access the website, if something goes wrong, make sure that it is printed at the standard level, it will be written to the trace utility. Use "python -m win32traceutil" to see the result of the trace.

It is important to understand the basic process in order to run the ISAPI application. I suggest first getting a WSGI welcome application running under ISAPI_WSGI. Here's an earlier version of the hook script I used to verify that I get CherryPy to work with my web server.

 #!python """ Things to remember: easy_install munges permissions on zip eggs. anything that installed in a user folder (ie setup develop) will probably not work. There may still exist an issue with static files. """ import sys import os import isapi_wsgi # change this to '/myapp' to have the site installed to only a virtual # directory of the site. site_root = '/' if hasattr(sys, "isapidllhandle"): import win32traceutil appdir = os.path.dirname(__file__) egg_cache = os.path.join(appdir, 'egg-tmp') if not os.path.exists(egg_cache): os.makedirs(egg_cache) os.environ['PYTHON_EGG_CACHE'] = egg_cache os.chdir(appdir) import cherrypy import traceback class Root(object): @cherrypy.expose def index(self): return 'Hai Werld' def setup_application(): print "starting cherrypy application server" #app_root = os.path.dirname(__file__) #sys.path.append(app_root) app = cherrypy.tree.mount(Root(), site_root) print "successfully set up the application" return app def __ExtensionFactory__(): "The entry point for when the ISAPIDLL is triggered" try: # import the wsgi app creator app = setup_application() return isapi_wsgi.ISAPISimpleHandler(app) except: import traceback traceback.print_exc() f = open(os.path.join(appdir, 'critical error.txt'), 'w') traceback.print_exc(file=f) f.close() def install_virtual_dir(): import isapi.install params = isapi.install.ISAPIParameters() # Setup the virtual directories - this is a list of directories our # extension uses - in this case only 1. # Each extension has a "script map" - this is the mapping of ISAPI # extensions. sm = [ isapi.install.ScriptMapParams(Extension="*", Flags=0) ] vd = isapi.install.VirtualDirParameters( Server="CherryPy Web Server", Name=site_root, Description = "CherryPy Application", ScriptMaps = sm, ScriptMapUpdate = "end", ) params.VirtualDirs = [vd] isapi.install.HandleCommandLine(params) if __name__=='__main__': # If run from the command-line, install ourselves. install_virtual_dir() 

This script performs several actions. It (a) acts as an installer, installing itself in IIS [install_virtual_dir], (b) contains the entry point when IIS loads the DLL [__ExtensionFactory__], and (c) creates the CherryPy WSGI instance used by the ISAPI [setup_application] handler.

If you put this in your \ inetpub \ cherrypy directory and run it, it will try to install itself in the root of your IIS website called "CherryPy Web Server".

You can also see my production website code , which reformatted it all into different modules.

+10
source

All Articles