0

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?

  • 1
    Possible duplicate of [How do you set up a Python WSGI server under IIS?](https://stackoverflow.com/questions/47253/how-do-you-set-up-a-python-wsgi-server-under-iis) – snakecharmerb Nov 16 '19 at 08:41

1 Answers1

2

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.

enter image description here

4.add site in iis with your cherrypy app path

enter image description here

5.select your site name then double click on the handler mapping feature of iis from the middle pane.

enter image description here

6.in handler mapping select add module mapping from the action pane.

enter image description here

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:

enter image description here

8.Set the PYTHONPATH variable(your cherrypy app folder path):

enter image description here

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):

enter image description here

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.

enter image description here

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)
Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26
  • I appreciate this. I am using python 64 bit. Do i have to use the 32 bit version for this to work ? – Cameron Sorensen Nov 18 '19 at 23:26
  • @CameronSorensen in my opinion no need to change with 32 bit. which python version you are using make sure it is after 3.6 because iis does not support lower than this? I also test with the 64-bit python you can see [here](https://i.imgur.com/xN76cUS.png) – Jalpa Panchal Nov 19 '19 at 02:06
  • If you feel my answer helps you, please mark it as an answer. This will help other people who face the same issue. – Jalpa Panchal Nov 19 '19 at 02:09
  • I am using python 3.7.2. I cannot get it working i have followed your steps for the past three hours. everytime i get "error 404" when i use localhost:8063/cherrypy – Cameron Sorensen Nov 19 '19 at 02:45
  • did you assign iis_iusrs and iusr permission to the python and site folder? could you share an error message screenshot? – Jalpa Panchal Nov 19 '19 at 03:01
  • no i will try that right now. one second. here is the error. [error message](https://i.imgur.com/1vKLiwh.png) adding iis_iusrs and iusr permission to the python and site folder and will try again. i will add another comment once done – Cameron Sorensen Nov 19 '19 at 03:06
  • do not forget to restart the iis server and site after doing changes. – Jalpa Panchal Nov 19 '19 at 03:12
  • It is still doing the same thing. both folders have iis_usrs and iusr permission to the path. i dont know what i am doing wrong. – Cameron Sorensen Nov 19 '19 at 03:23
  • could you share the iis site advance setting screenshot? and just click on browse after a click on site name. – Jalpa Panchal Nov 19 '19 at 03:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/202614/discussion-between-cameron-sorensen-and-jalpa-panchal). – Cameron Sorensen Nov 19 '19 at 04:35
  • @CameronSorensen please check the message – Jalpa Panchal Nov 19 '19 at 05:48
  • 1
    **to anybody trying to do this** make sure directory browsing is enabled in iis. in web.config replace resourceType'"File" with resourceType="Unspecified" requireAccess="Script" – Cameron Sorensen Nov 19 '19 at 06:28