<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: import arcpy fails with cgi script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/import-arcpy-fails-with-cgi-script/m-p/627081#M48849</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your problem is likely due to a CGI script starting from scratch for each request &amp;amp; IIS is timing out because the script takes too long to start. You might want to look into a framework like FastCGI or Web.py. That way, your ArcGIS Engine (via arcpy) is fired up once and left running until the server shuts down. Each request of the FastCGI/Web.py script reuses the same objects from modules like arcpy, psycopg2, etc instead of recreating them each time. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FastCGI on IIS: &lt;/SPAN&gt;&lt;A href="http://www.iis.net/downloads/microsoft/fastcgi-for-iis"&gt;http://www.iis.net/downloads/microsoft/fastcgi-for-iis&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;Web.py: &lt;/SPAN&gt;&lt;A href="http://webpy.org/"&gt;http://webpy.org/&lt;/A&gt;&lt;SPAN&gt; (on IIS: &lt;/SPAN&gt;&lt;A href="http://webpy.org/cookbook/iis7_iis6_windows_pyisapie"&gt;http://webpy.org/cookbook/iis7_iis6_windows_pyisapie&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Dec 2013 15:07:39 GMT</pubDate>
    <dc:creator>JohnReiser</dc:creator>
    <dc:date>2013-12-04T15:07:39Z</dc:date>
    <item>
      <title>import arcpy fails with cgi script</title>
      <link>https://community.esri.com/t5/python-questions/import-arcpy-fails-with-cgi-script/m-p/627079#M48847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;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 &amp;amp; Surface Leases", df)[0]


dq = "(INVOICENUMBER = '" + agn + "'" + ")"
lyr.definitionQuery = dq
df.extent = lyr.getExtent()

for elm in arcpy.mapping.ListLayoutElements(mapDoc, "TEXT_ELEMENT"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.name == "INVOICENUMBER":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 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 '&amp;lt;html&amp;gt; '
print '&amp;lt;head&amp;gt; '
print '&amp;lt;meta http-equiv="refresh" content="0;url='
print URL
print '" /&amp;gt; '
print '&amp;lt;title&amp;gt;Request Submitted, Redirecting...&amp;lt;/title&amp;gt; '
print '&amp;lt;/head&amp;gt; '
print '&amp;lt;body&amp;gt; '
print 'Loading map...'
print URL
print '&amp;lt;/body&amp;gt; '
print '&amp;lt;/html&amp;gt;'

lyr.definitionQuery = ""

del mapDoc

sys.exit()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a simple default site set up on my computer using IIS 7. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;James&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Aug 2013 21:45:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/import-arcpy-fails-with-cgi-script/m-p/627079#M48847</guid>
      <dc:creator>JamesGustine</dc:creator>
      <dc:date>2013-08-19T21:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: import arcpy fails with cgi script</title>
      <link>https://community.esri.com/t5/python-questions/import-arcpy-fails-with-cgi-script/m-p/627080#M48848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having the same issue. At 10.0, I did successfully integrate Python CGIs using arcpy and implemented a number of applications with that approach. We're migrating to 10.1 and concurrently I'm trying to update my CGI scripts, but they've been failing too, with a 502 error. However, when I swap out my cgiFieldStorage() variables with hardcoded variables, the scripts run\output as they should.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you get an update or solution regarding this issue, I'd love to hear about it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Eric&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 17:29:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/import-arcpy-fails-with-cgi-script/m-p/627080#M48848</guid>
      <dc:creator>ColletonGISAdmin</dc:creator>
      <dc:date>2013-12-03T17:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: import arcpy fails with cgi script</title>
      <link>https://community.esri.com/t5/python-questions/import-arcpy-fails-with-cgi-script/m-p/627081#M48849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your problem is likely due to a CGI script starting from scratch for each request &amp;amp; IIS is timing out because the script takes too long to start. You might want to look into a framework like FastCGI or Web.py. That way, your ArcGIS Engine (via arcpy) is fired up once and left running until the server shuts down. Each request of the FastCGI/Web.py script reuses the same objects from modules like arcpy, psycopg2, etc instead of recreating them each time. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FastCGI on IIS: &lt;/SPAN&gt;&lt;A href="http://www.iis.net/downloads/microsoft/fastcgi-for-iis"&gt;http://www.iis.net/downloads/microsoft/fastcgi-for-iis&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;Web.py: &lt;/SPAN&gt;&lt;A href="http://webpy.org/"&gt;http://webpy.org/&lt;/A&gt;&lt;SPAN&gt; (on IIS: &lt;/SPAN&gt;&lt;A href="http://webpy.org/cookbook/iis7_iis6_windows_pyisapie"&gt;http://webpy.org/cookbook/iis7_iis6_windows_pyisapie&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 15:07:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/import-arcpy-fails-with-cgi-script/m-p/627081#M48849</guid>
      <dc:creator>JohnReiser</dc:creator>
      <dc:date>2013-12-04T15:07:39Z</dc:date>
    </item>
  </channel>
</rss>

