Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Created October 23, 2014 17:56
Show Gist options
  • Save amarinelli/938d90003c6501ac440d to your computer and use it in GitHub Desktop.
Save amarinelli/938d90003c6501ac440d to your computer and use it in GitHub Desktop.
Workaround to validate an AGS connection file
import arcpy
import os
outdir = r'C:\TEMP'
out_folder_path = outdir
out_name = 'test_connection.ags'
server_url = 'http://localhost:6080/arcgis/admin'
username = 'admin'
password = 'admin'
agsFile = os.path.join(outdir, out_name)
if os.path.exists(agsFile):
os.remove(agsFile)
arcpy.mapping.CreateGISServerConnectionFile("ADMINISTER_GIS_SERVICES",
out_folder_path,
out_name,
server_url,
"ARCGIS_SERVER",
True,
"#",
username,
password,
"SAVE_USERNAME")
try:
folders = arcpy.ListDataStoreItems(agsFile, "FOLDER")
print folders
except:
# Handle bad connection file
print "The connection failed"
print "\ndone"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment