IO error on bulk MXD publishing to ArcGIS Server using Python

07-14-2020 08:54 AM
New Contributor III
import arcpy
import os

wrkspc = 'C:/Project/BULK/'
#mxd = arcpy.mapping.MapDocument('BULK_Test.mxd')

con = 'AGSconnectionfile.ags'

for (wrkspc, dirs, files) in os.walk(wrkspc):
for fl in files:
if fl.lower().endswith(".mxd"):

mxd = arcpy.mapping.MapDocument(os.path.join(wrkspc, fl))
# Provide other service details
service = mxd
sddraft = 'C:/Project/BULK/' + str(mxd) + '.sddraft'
sd = 'C:/Project/BULK/' + str(mxd) + '.sd'
summary = 'BULK_Test'
tags = 'BULK_Test'

# Create service definition draft
arcpy.mapping.CreateMapSDDraft(mxd, sddraft, mxd, 'ARCGIS_SERVER', con, True, "Project", summary, tags)

# Analyze the service definition draft
analysis = arcpy.mapping.AnalyzeForSD(sddraft)

# Print errors, warnings, and messages returned from the analysis
print "The following information was returned during analysis of the MXD:"
for key in ('messages', 'warnings', 'errors'):
print '----' + key.upper() + '---'
vars = analysis[key]
for ((message, code), layerlist) in vars.iteritems():
print ' ', message, ' (CODE %i)' % code
print ' applies to:',
for layer in layerlist:

# Stage and upload the service if the sddraft analysis did not contain errors
if analysis['errors'] == {}:
# Execute StageService. This creates the service definition.
arcpy.StageService_server(sddraft, sd)

# Execute UploadServiceDefinition. This uploads the service definition and publishes the service.
arcpy.UploadServiceDefinition_server(sd, con)
print "Service successfully published"
print "Service could not be published because errors were found during analysis."

print arcpy.GetMessages()

I have a folder of MXDs and I want to publish all of them in batch to a single ArcGIS Server. I've had success using Python on a single MXD, but when I add a loop into the code so that I can do multiple services at once, I run into errors that I'm unable to troubleshoot. I found the code below on ArcGIS Enterprise site and tried to modify it for batch processing.

I've tried as a standalone script and from within ArcMap 10.7.1. The error:

File "C:\Project\BULK\", line 29, in <module>IOError: Operation on file C:\Users\...\Temp\{67337BAB-1DDF-4A39-9FB4-B7C8EF8597B0}\<geoprocessing Map object object at 0x036534A0>.sddraft failed. Unknown error.

I am doing this with an active connection to the ArcGIS Server (10.8) in ArcCatalog.

0 Kudos
1 Reply
MVP Honored Contributor

Dave Grolling


would help the reading of the script and provide line numbers for reference

... sort of retired...
0 Kudos