Select to view content in your preferred language

Is it possible to use a registered layer to create a SDDraft using Python?

171
2
08-14-2024 07:35 AM
sophered
Occasional Contributor

Currently trying to use a registered feature layer to create an sddraft, stage it and then upload to overwrite an existing service definition on portal. However I am continually running into this error at the staging part:

ERROR 001272: Analyzer errors were encountered ([{"code":"00102","message":"Map does not contain a required layer type for web feature layer","object":"Map"}]).
Failed to execute (StageService).

 

 

outdir = r"file path pointing to a folder" 
service_name = "name of sd to be overwritten in portal"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)

aprx =
arcpy.mp.ArcGISProject(r"projectfilepath.aprx")
m = aprx.listMaps()[0]
selected_layer = m.listLayers()[0]

server_type = "HOSTING_SERVER"
federated_server_url = "server pointing to layer/sd to be overwritten"

sddraft = m.getWebLayerSharingDraft(server_type, 'FEATURE', service_name)
sddraft.overwriteExistingService = True
sddraft.federatedServerUrl = federated_server_url

sddraft.exportToSDDraft(sddraft_output_filename)
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, server_type)

 

Does anyone know why I am running into this error? 

 

0 Kudos
2 Replies
BrandonMcAlister
Frequent Contributor

@sophered add the line aprx.save() on line 19 and it should work

Thanks,
Brandon
0 Kudos
TonyAlmeida
Frequent Contributor

Line 8 & 9  have issues. Does your map contains other types of layers (like raster layers, annotation layers, or group layers), these may cause issues when creating a web feature layer. Check that the map and layers have appropriate settings for publishing. For example, make sure that they have valid/correct coordinate systems and necessary permissions. You could also, in ArcGIS Pro, manually attempt to publish the web layer through the GUI, and observe if any errors or warnings appear.

0 Kudos