Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

import arcpy fails with cgi script

$
0
0
Hello,

I'm looking to get this simple map export to run via an url and am running into issues when importing arcpy. It runs fine locally, but gives a 502-webserver recieved and invalid response while acting as a gateway or proxy server when run from another computer.

Code:

import cgitb, sys, string, os, arcpy, cgi
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print
#print ""
form = cgi.FieldStorage()
arg = form.getvalue('agn')

#tMapDir = tMapDir
tMapDir = r"C:\inetpub\wwwroot\cgi-bin\Map.pdf"

arcpy.env.overwriteOutput = True

# Get Parameters
agn = arg

# Set Map
mapDoc = arcpy.mapping.MapDocument(r"C:\inetpub\wwwroot\cgi-bin\ContractReport.mxd")
df = arcpy.mapping.ListDataFrames(mapDoc)[0]
lyr = arcpy.mapping.ListLayers(mapDoc, r"ROWs, CAs & Surface Leases", df)[0]


dq = "(INVOICENUMBER = '" + agn + "'" + ")"
lyr.definitionQuery = dq
df.extent = lyr.getExtent()

for elm in arcpy.mapping.ListLayoutElements(mapDoc, "TEXT_ELEMENT"):
    if elm.name == "INVOICENUMBER":
        elm.text = agn

arcpy.mapping.ExportToPDF(mapDoc, tMapDir, resolution="300", image_quality="NORMAL", layers_attributes="NONE", georef_info=False, jpeg_compression_quality="80")

#Set output file


URL = "http://localhost/cgi-bin/Map.pdf"

print "Content-type:text/html\r\n\r\n"
print '<html> '
print '<head> '
print '<meta http-equiv="refresh" content="0;url='
print URL
print '" /> '
print '<title>Request Submitted, Redirecting...</title> '
print '</head> '
print '<body> '
print 'Loading map...'
print URL
print '</body> '
print '</html>'

lyr.definitionQuery = ""

del mapDoc

sys.exit()

The problem is definetly with the import arcpy as I can run a simple helloworld.py with standard py library imports (os, sys, cgi, string, stc) and it is accessbile from other machines.

I have a simple default site set up on my computer using IIS 7.

Any thoughts on getting arcpy to import for cgi scripts from other computers? I know importing arcpy checks out a license and does wires up arcobjects. Is accesssing the module from a URL even possible?

Thanks,

James

Viewing all articles
Browse latest Browse all 2485

Trending Articles