Cherrypy with arcpy

2481
14
01-19-2017 02:03 AM
Thanh_NgocDao
New Contributor

Hello everybody,

Currently i'm developing an API that do some basic calculation (polygon area ... ) using arcpy. I'm using bottle.py with cherrypy as webserver.

At first i used the WSGIRef (default webserver of bottle.py, single-thread) and everything is fine but after switching to cherrypy (multi-threaed webserver), my code suddenly went down, look closely in to my source code it fail in these line:

             arcpy.env.workspace = OutputLocation

Have someone ever facing this problem before?

0 Kudos
14 Replies
FC_Basson
MVP Regular Contributor

I think the cellSize line needs to refer to a cellsize value and not the raster.  So you need to get the raster properties first to get the Elevation_Raster cellsize

cs = arcpy.GetRasterProperties_management(Elevation_Raster, "CELLSIZEX")‍‍‍
arcpy.env.cellSize = cs.getOutput(0)‍‍
0 Kudos
Thanh_NgocDao
New Contributor

Even though i remove that line, it still produce the same error on: arcpy.env.workspace = OutputLocation . That error never happen when i use old webserver. Thank you very much

0 Kudos
FC_Basson
MVP Regular Contributor

Make sure the output location format is correct - see Dan Patterson‌'s blog /blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python 

0 Kudos
Thanh_NgocDao
New Contributor

I think it's correct Mr.Basson, because this code run fine with WSGIRef webserver, but can't work with cherrypy, i also print the output location and it still correct

0 Kudos
FC_Basson
MVP Regular Contributor

So you've changed servers - is the output location still the same and a valid location?

0 Kudos
Thanh_NgocDao
New Contributor

Yes, it's still the same and valid Mr.Basson. In fact it raise the error at that step and the error is: AttributeError: ERROR 87934 ... As i know usually AttributeError is raised because there is no that attribute (env or workspace)

0 Kudos
DanPatterson_Retired
MVP Emeritus

does ...    import arcpy  .... work?  If it doesn't, the location of arcmap and hence arcpy is unknown... if it does, do as fcbassongis‌ says

0 Kudos
Thanh_NgocDao
New Contributor

Yes, the import arcpy work Mr.Patterson

0 Kudos
DanPatterson_Retired
MVP Emeritus

Good... now can you get a list of files in the folder/workspace?  or examine the contents of a featureclass (ie ListFeatureClasses would be useful

0 Kudos