arcpy from a web page

623
1
Jump to solution
05-01-2019 12:59 PM
BillChappell
Occasional Contributor II

Hi, we're constantly exporting data out of our database. We have python scripts that accept parameters and then export and zip up the shapefiles files. From our dashboard, I'd like to put a form where we could select a type and then hit a button, this would then pass the parameter to my python script and create the shapefile for download. 

Why I can program in JS, Python, PHP and Node, I have not been able to get the python working on our server. I know there is Django, Flask, and others, but I'm not sure which one would be the best choice to work with ArcPy. 

I noticed the documentation is also all over the place, is there a cookbook or instructions that demonstrate this concept? I found the thread Exposing-Arcpy-Python-Script-to-Web but that was 8 years ago, anything newer and more complete?

0 Kudos
1 Solution

Accepted Solutions
BillChappell
Occasional Contributor II

Figured it out. You can set up an ISAPI handler to pass requests to py files to the python executable.

 

Like step 7 here: https://stackoverflow.com/questions/6823316/python-on-iis-how

 

This worked for me, and since the site is internal and not heavily used, and I'm still prototyping a solution, I was able to avoid installing a larger framework.

 

After following the instructions I have a virtual folder called py, so I created a simple python file and placed it into this folder.

 

I called it helloworld.py just to test it. Its contents.

-----------helloworld.py script --------------------------

print('Content-Type: text/plain')

print('')

print('Hello, world!')

print('')

 

import os, sys

 

GET={}

args=os.getenv("QUERY_STRING").split('&')

 

for arg in args:

    t=arg.split('=')

    if len(t)>1: k,v=arg.split('='); GET=v

 

x = GET.get('user_name')

 

print(x)

 

-------------------------------------------------------------

Next, I opened a browser and typed:

 

http://localhost/py/helloworld.py?user_name=Bill

 

The page responded:

Hello, world!

 

Bill

 

At this point, I have a python script on a web server that I can call by a url, and it runs. Next stop to create a webpage, that has a select (picklist) and a button, when pressed, fires off a ajax get to my script and have my script read the parameter and run. But that's just JavaScript.

View solution in original post

1 Reply
BillChappell
Occasional Contributor II

Figured it out. You can set up an ISAPI handler to pass requests to py files to the python executable.

 

Like step 7 here: https://stackoverflow.com/questions/6823316/python-on-iis-how

 

This worked for me, and since the site is internal and not heavily used, and I'm still prototyping a solution, I was able to avoid installing a larger framework.

 

After following the instructions I have a virtual folder called py, so I created a simple python file and placed it into this folder.

 

I called it helloworld.py just to test it. Its contents.

-----------helloworld.py script --------------------------

print('Content-Type: text/plain')

print('')

print('Hello, world!')

print('')

 

import os, sys

 

GET={}

args=os.getenv("QUERY_STRING").split('&')

 

for arg in args:

    t=arg.split('=')

    if len(t)>1: k,v=arg.split('='); GET=v

 

x = GET.get('user_name')

 

print(x)

 

-------------------------------------------------------------

Next, I opened a browser and typed:

 

http://localhost/py/helloworld.py?user_name=Bill

 

The page responded:

Hello, world!

 

Bill

 

At this point, I have a python script on a web server that I can call by a url, and it runs. Next stop to create a webpage, that has a select (picklist) and a button, when pressed, fires off a ajax get to my script and have my script read the parameter and run. But that's just JavaScript.