Reputation: 53
I am looking for a solution to link IIS and Cherrypy.
I would like a specific explanation of doing this for Cherrypy as all others are for other applications like flask and django.
I can call the functions getHeight and getWidth by
using the call http://0.0.0.0:8080/getHeight
import cherrypy
import tileProvider
import time
class MyWebService(object):
provider = TileProvider('myPicture.JPEG')
@cherrypy.expose
def getHeight(self):
return str(MyWebService.provider.getHeight())
@cherrypy.expose
def getWidth(self):
return str(MyWebService.provider.getWidth())
if __name__ == '__main__':
IPv4 = socket.gethostbyname(socket.gethostname())
config = {'server.socket_host': IPv4,
'server.socket_port': 8080}
cherrypy.config.update(config)
cherrypy.quickstart(MyWebService())
So now how would create the same thing except hosted from IIS and not CherryPy's built in WebServer.
Does anybody have any useful pointers or links for me to follow?
Upvotes: 0
Views: 818
Reputation: 12844
to configure Cherrypy app in iis you could follow the below steps:
1.Run below command to install cherrypy
pip install cherrypy
2.install wfastcgi and enable it:
pip install wfastcgi
fastcgi-enable
3.enable iis cgi feature.
4.add site in iis with your cherrypy app path
5.select your site name then double click on the handler mapping feature of iis from the middle pane.
6.in handler mapping select add module mapping from the action pane.
executable path value: C:\Python37-32\python.exe|C:\Python37-32\Lib\site-packages\wfastcgi.py
C:\Python37-32 is your python path.
7.Now go back and again select the server name and select fast CGI setting from the middle pane. Double click it, then click the “…” for the Environment Variables collection to launch the EnvironmentVariables Collection Editor:
8.Set the PYTHONPATH variable(your cherrypy app folder path):
9.And the WSGI_HANDLER (my app is named app.py so the value is app.wsgiapp — if yours is named site.py it would be site.app.wsgiapp or similar):
You might have to restart the Server and the website after configuration changes.
Make sure you run the application pool identity with one of the admin user or if its running with App pool identity then make sure you provide full permission to the site folder which is C:\cherryapp and the python folder C:\Python37-32 or assign the iis_iusrs and iusr permission.
app.py:
import cherrypy
class Root:
@cherrypy.expose
def index(self):
return 'Hello CherryPy!'
@cherrypy.expose
def greet(self, name):
return 'Greetings, {0}'.format(name)
url_prefix = '/cherrypy'
cherrypy.config.update({'engine.autoreload.on': False})
cherrypy.server.unsubscribe()
cherrypy.engine.start()
wsgiapp = cherrypy.tree.mount(Root(), url_prefix)
Upvotes: 2