Select to view content in your preferred language

Geoprocessing with CherryPy web framework

1388
5
07-09-2012 03:01 PM
nickmassaro
Emerging Contributor
I???m trying to return data to a web page from a simple processioning procedure. I keep getting the following error ???self._gp.SearchCursor(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function.??? The processioning function works fine standalone but fails when ran with through CherryPy.
I think it???s a pathing issue but haven???t had any luck solving it.[ATTACH=CONFIG]15889[/ATTACH]

Any help would be greatly appreciated.

Code follows as well as being attached with table.

##
import cherrypy
import arcpy

class StartPage:

  def index(self):
    # This is the starting web page for the HOA selection application
    return '''
      <p><a href="http://TheServerName:8080/get_database" target="_parent">database pull</a></p>
      <p><a href="http://TheServerName:8080/get_text" target="_parent">text pull</a></p>'''
  index.exposed = True

  def get_database(self):
    info = data_extract()
    return info
  get_database.exposed = True

  def get_text(self):
    return """Great! this worked<p><p><a href="http://TheServerName:8080/" target="_parent">back</a></p>
  </p>

  """
  get_text.exposed = True

def data_extract():
  Notification_Table = "C:/web.dbf"
  rows = arcpy.SearchCursor(Notification_Table)
  row = rows.next()
  return_string = ""
  while row:
    name = row.getValue("NAME")
    return_string = return_string + 'name: %s\n' % name
    row = rows.next()
  return return_string

import os.path
hoaconf = os.path.join(os.path.dirname(__file__), 'hoa.conf')

if __name__ == '__main__':
    cherrypy.quickstart(StartPage(), config=hoaconf)
else:
    cherrypy.tree.mount(StartPage(), config=hoaconf)
##
0 Kudos
5 Replies
JasonScheirer
Esri Alum
Make sure the server you're using (whether it's the built-in CherryPy one or whatever standard WSGI server you're using) isn't threaded.
0 Kudos
nickmassaro
Emerging Contributor
Thanks Jason. Is there a WSGI server you would recommend?
0 Kudos
nickmassaro
Emerging Contributor
From - http://forums.arcgis.com/threads/34814-Exposing-Arcpy-Python-Script-to-Web

>>
There's WSGI, which is an open standard that allows you to develop in Django, or Pyramid, or web.py, or flask, or any of a number of other options. Flask or web.py are probably your best bet for porting from CGI.

If you run a web application that handles multiple requests in the same process (that is, running a Python WSGI server behind your IIS instance) then you don't incur the overhead of importing arcpy over and over.
>>
0 Kudos
JasonScheirer
Esri Alum
Unfortunately, I'm not super knowledgeable about the state of Python HTTP on Windows. However, you may find luck with gevent's WSGI server (example) as it uses greenlets in an event loop instead of threaded workers.
0 Kudos
nickmassaro
Emerging Contributor
I ended up driving the screw in with a hammer.
CGI and python.
0 Kudos