Issues with publishing a Map in an ArcGIS Pro project as a Map Service to ArcGIS Server

01-14-2020 12:22 AM
Esri Contributor


I'm trying to get the following code running. This code is a copy from this link:

CreateSharingDraft—Sharing module | ArcGIS Desktop 

import arcpy 
import os 
# Set output file names 
outdir = r"C:\Project\Output" 
service = "MapServiceDraftExample" 
sddraft_filename = service + ".sddraft" 
sddraft_output_filename = os.path.join(outdir, sddraft_filename) 
# Reference map to publish 
aprx ="C:\Project\World.aprx") 
m = aprx.listMaps("World")[0] 
# Create MapServiceDraft and set service properties 
service_draft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "MAP_SERVICE", service, m) 
service_draft.targetServer = r"C:\Project\ (publisher).ags" 
# Create Service Definition Draft file
# Stage Service 
sd_filename = service + ".sd" 
sd_output_filename = os.path.join(outdir, sd_filename) 
arcpy.StageService_server(sddraft_output_filename, sd_output_filename) 
# Share to portal 
print("Uploading Service Definition...") 
arcpy.UploadServiceDefinition_server(sd_output_filename, r"C:\Project\ (publisher).ags") 
print("Successfully Uploaded service.")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I've changed the variable accordingly, however I get this error even though I can connect to the server (.ags) in ArcGIS Pro:

Are there any other options besides "STANDALONE_SERVER" in

service_draft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "MAP_SERVICE", service, m)?


Tags (1)
0 Kudos
1 Reply
by Anonymous User
Not applicable

Hi @MehdiPira1,

I see this is back from January so I'm not sure if you've resolved your issue or not.

I'm wondering if you are needing to share as a service or would hosting the layer serve your purpose?

I'm currently in the process of automating many of the services we were running here due to some software versioning issues we encountered (we're still on 10.4 😑)

Feature Sharing Draft  seems to be the "go-to" answer for automating overwrites but there are still a lot of rough edges with the process to be honest. When you use the script as described in the document most of the configurable properties you may have set when originally hosting the layer revert to the default... the two biggest ones in my case are timezone and sharing options.

The timezone issue has been resolved and I've attached the script in a txt file. I'm still working on trying to fix the sharing issue I'm having because it's not a huge benefit to have to go in and manually update the sharing on all these layers everyday just to have it revert to not shared every evening.


I hope this helped or that you got your problem solved already

0 Kudos