Hi all,
I want to use python to upload a web layer as https://pro.arcgis.com/de/pro-app/3.1/tool-reference/server/upload-service-definition.htm shows, if the layer is already in the map view, everything is ok
however, I want to upload the data directly from geodatabase, and I don't know what to do. Here's what I tried:
and the error I got:
what should I do?
try this instead
aprx = arcpy.mp.ArcGISProject("Current") ### Bug Fix ### aprx.closeViews("MAPS") aprx.listMaps("Map")[0].openView() aprx.save()
Hi @BrandonMcAlister ,
this works perfectly! thank you very much!
Best,
Ziqing
@ZiqingYu
Since you pointed out the .addDataFromPath was causing the issue I was able to reproduce that as the cause of the error.
I found that using .addDataFromPath then restarting ArcPro and running the block of code where I attempt to publish will work 100% of the time (5/5 times to be exact).
So I assumed that the map object just needed to be refreshed: adding this line of code seems to work for me test and let me know if it works for you. I have this done before I create the sddraft using .getWebLayerSharingDraft().
aprx = arcpy.mp.ArcGISProject("CURRENT") aprx.closeViews("MAPS") aprx.listMaps("Map")[0].openView()
@ZiqingYu would you be surprised to find out the the fix I implemented last week does not work today and I am now receiving the error again.
I do use add data from path as my script creates new layers and tables that are being published. When I add the feature manually I still receive the error though.
Hi Brandon,
Actually I'm using this code sample from the same page, the lines you mentioned are not used by me.
import arcpy import os # Sign in to portal arcpy.SignInToPortal("https://www.arcgis.com", "MyUserName", "MyPassword") # Set output file names outdir = r"C:\Project\Output" service_name = "FeatureSharingDraftExample" 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) # Reference layers to publish aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx") m = aprx.listMaps('World')[0] selected_layer = m.listLayers()[0] selected_table = m.listTables()[0] # Create FeatureSharingDraft server_type = "HOSTING_SERVER" sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name, [selected_layer, selected_table]) # Create Service Definition Draft file sddraft.exportToSDDraft(sddraft_output_filename) # Stage Service print("Start Staging") arcpy.server.StageService(sddraft_output_filename, sd_output_filename) # Share to portal print("Start Uploading") arcpy.server.UploadServiceDefinition(sd_output_filename, server_type) print("Finish Publishing")
And this code actually works if I drag and drop the data from geodatabase into the project view and then run the publish code.
It doesn't work when I use
selected_layer = m.addDataFromPath(shape_in_gdb)
to do this step, which confused me.
I'm assuming we used the same code sample and part of that sample has something like this in it:
#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 = ""#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 sddraftfile f = open(sddraftpath, 'w') docs.writexml(f) f.close()
I have this same issue and I just discovered today that removing line 23-26 removes the error and allows it to publish. Hope this helps
To non German speaker: the error means: The chosen Layer hat no required layer-typ for web-feature-layer, object: map
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.