Hi, trying to use arcpy to publish and overwrite a service that has the WMS capability enabled. Federated Server/Portal 10.8.1. Code below isn't my full code, but I think I've reduced it down to what is relevant. The problem is that when the final line runs that stages the service, it does an analyse and throws and error:
ERROR 001272: Analyzer errors were encountered ([{"code":"00297","message":"WMS layers must be shared with everyone","object":"MyServiceName"}]).
We used to have this working with 10.7 and with ArcMap's arcpy, but this is trying to use a Pro 2.7 map. Not sure how to set sharing public before the arcpy.UploadServiceDefinition_server. The service is already published and both the regular map service and WMS items are already shared public.
import arcpy
import os
import xml.dom.minidom as DOM
# Sign into Portal and publish
arcpy.SignInToPortal(portal_URL, portal_pub_user, portal_pub_pass)
# Create MapImageSharingDraft and set metadata, portal folder, and server folder properties
sharing_draft = MAP.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", service_name)
sharing_draft.summary = "summary"
sharing_draft.tags = "tags"
sharing_draft.description = "description"
sharing_draft.credits = "credits"
sharing_draft.useLimitations = "useLimitations "
sharing_draft.serviceName = service_name
sharing_draft.federatedServerUrl = server_URL
sharing_draft.serverFolder = "serverFolder"
sharing_draft.portalFolder = "portalFolder"
sharing_draft.overwriteExistingService = True
# Create Service Definition Draft file
sharing_draft.exportToSDDraft(sddraft_output_filename)
# Edit SD Draft XML to enable WMS
doc = DOM.parse(sddraft_output_filename)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
if desc.parentNode.tagName == 'SVCManifest':
if desc.hasChildNodes():
desc.firstChild.data = 'esriServiceDefinitionType_Replacement'
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName we want to enable.
if typeName.firstChild.data == 'WMSServer':
extension = typeName.parentNode
keys = doc.getElementsByTagName('Key')
for extElement in extension.childNodes:
# Enabled WMS
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
f = open(sddraft_output_filename, 'w')
doc.writexml(f)
f.close()
# Stage Service
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)
# Share to portal
arcpy.UploadServiceDefinition_server(in_sd_file=sd_output_filename, in_server=portal_URL, in_folder_type="EXISTING", in_override = "OVERRIDE_DEFINITION", in_public = "PUBLIC", in_organization = "SHARE_ORGANIZATION")