Select to view content in your preferred language

Publishing Feature Class returns error

221
7
Jump to solution
05-23-2024 07:22 AM
BrandonMcAlister
Occasional Contributor

Hey Everyone,

 

#Publish layer to Geohub

#Create FeatureSharing draft object and allow overwriting 
server_type = "HOSTING_SERVER"
service_type = "FEATURE"
service_name = "Deed_Notice_Inspections"

FSD = MP.getWebLayerSharingDraft(server_type, service_type, service_name, Publish) #creates draft service definition
#Assign Feature Service Definition properties
FSD.overwriteExistingService = True #overwrites existing layer on portal service
FSD.allowExporting = False #allow exporting of feature layer
FSD.credits = credits #sets credits
FSD.description = description #Sets description
FSD.offine = False #must be connected to portal to create service definition
FSD.portalFolder = "Deed Notice Inspections" #portal where feature will be saved
FSD.overwriteExistingService = True #overwrites existing layer on portal service
FSD.summary = summary #sets summary
FSD.tags = tags #sets tags

#create path to Service definition draft file
sddraft = service_name + ".sddraft"
sddraftpath = os.path.join(defaultfolder, sddraft)

#Create Service definition draft file
FSD.exportToSDDraft(sddraftpath)

#read draft file
docs = DOM.parse(sddraftpath)
key_list = docs.getElementsByTagName('Key')
value_list = docs.getElementsByTagName('Value')

#Sharing level
Share_Organization = "false"
Share_Everyone = "false"
Share_Group = "true"

#Sharing to Deed Notice Inspection Tool Group
GroupID = "a49bff8206a1412991219a39ae4067ed"

#set sharing values
for i in range(key_list.length):
    if key_list[i].firstChild.nodeValue == "PackageUnderMyOrg":
        value_list[i].firstChild.nodeValue = Share_Organization
    if key_list[i].firstChild.nodeValue == "PackageIsPublic":
        value_list[i].firstChild.nodeValue = Share_Everyone
    if key_list[i].firstChild.nodeValue == "PackageShareGroups":
        value_list[i].firstChild.nodeValue = Share_Group
    if Share_Group == "true" and key_list[i].firstChild.nodeValue == "PackageGroupIDs":
        value_list[i].firstChild.nodeValue = GroupID

#write to sddraft file
f = open(sddraftpath, 'w')
docs.writexml(f)
f.close()

sd = service_name + ".sd"
sdpath = os.path.join(defaultfolder, sd)

#stage service
arcpy.SetProgressorLabel("Staging Service")
arcpy.server.StageService(sddraftpath, sdpath, 300)

#Share to portal
arcpy.SetProgressorLabel("Publishing Service")
arcpy.server.UploadService(sdpath, server_type)

 

 

In the attached code, I am trying to publish a feature layer and just the feature layer. everything works up until line 61 when I get error: ERROR 001272: Analyzer errors were encountered ([{"code":"00102","message":"Selected layer does not contain a required layer type for web feature layer","object":"Map"}]

EDIT: corrected error code message

It is my understanding that the way my script is set up is that instead of publishing the map as a web layer it will publish the feature class as a web feature layer. 

However, the error is saying that I am missing the Map object, which in my project has the default name "Map". 

If I instead try to publish the entire map I receive an error that says the feature layer path is inaccessible but it is saved in the default geodatabase for the project. 

 

I will update as I continue to troubleshoot the issue with any new developments.

Thanks,
Brandon
0 Kudos
1 Solution

Accepted Solutions
BrandonMcAlister
Occasional Contributor

combining the aprx.save() from this post https://community.esri.com/t5/arcgis-pro-questions/error-publishing-feature-layer-using-modelbuilder... 

with my above fix seems to have pacified the beast for now. 

### BUG FIX ###
aprx.closeViews("MAPS")
aprx.listMaps("Map")[0].openView()
aprx.save()

 

(I did not enjoy this)

 

Thanks,
Brandon

View solution in original post

0 Kudos
7 Replies
BrandonMcAlister
Occasional Contributor

I have written this script in ArcGIS Notebooks, and I broke up this code into separate blocks. Line 1-18 is now one block. on line 8 I parsed "FEATURE" instead of using a variable. Line 19-38 is a block and 40-54 is a block, and 56-65 is a block.

Prior to getting it to work I was using xml.dom.minidom.parse(sddraft) to look in the file at the values. Then I accidentally ran the final block and it worked. 

 

However, after changing my Project and coming back it failed again.

Thanks,
Brandon
0 Kudos
BrandonMcAlister
Occasional Contributor

Following the code sample on this page: https://pro.arcgis.com/en/pro-app/3.2/arcpy/sharing/featuresharingdraft-class.htm 

I have discovered that the line xml.dom.minidom().parse().writexml is what is causing the issue. In the code sample is is docs.writexml. Removing this line removes the error and allows the feature to publish to my portal.

 

Thanks,
Brandon
0 Kudos
BrandonMcAlister
Occasional Contributor

This was a temporary solution that does not work after the weekend. The demo this morning failed spectacularly.

Thanks,
Brandon
0 Kudos
BrandonMcAlister
Occasional Contributor

Well I went back to the drawing board and I have come to the conclusion that I have no idea what I am talking about.

Anyway I have discovered that the layer that is created I add to the map using .addDataFromPath. As another poster discovered that method is causing the issue for his script. While testing this out I discovered that creating the feature and adding it to the map then closing ArcPro and restarting allows the layer to publish without any issue.

I am assuming that I need to refresh the project and map to recognize the new feature class as that is basically what I am doing when I restart ArcPro.

 

"Sometimes the journey isn't worth the reward." 

Thanks,
Brandon
0 Kudos
BrandonMcAlister
Occasional Contributor

well adding the following line of code:

aprx.closeViews("MAPS")
aprx.listMaps("Map")[0].openView()

seems to solve the issue, however I cannot say this is will be the complete answer as I have already experience a fix that after 24 hours no longer worked. If it still works tomorrow I guess I have a solution.

Thanks,
Brandon
0 Kudos
BrandonMcAlister
Occasional Contributor

Well 20 minutes later and this no longer works. I had it working perfectly letting multiple users try it then restarted ArcPro as one final test just to watch my life flash before my eyes as my precious child decided to imploded and revert back to childish antics. 

Stay tuned for live updates as I continue to troubleshoot the issue

Thanks,
Brandon
0 Kudos
BrandonMcAlister
Occasional Contributor

combining the aprx.save() from this post https://community.esri.com/t5/arcgis-pro-questions/error-publishing-feature-layer-using-modelbuilder... 

with my above fix seems to have pacified the beast for now. 

### BUG FIX ###
aprx.closeViews("MAPS")
aprx.listMaps("Map")[0].openView()
aprx.save()

 

(I did not enjoy this)

 

Thanks,
Brandon
0 Kudos