AnsweredAssumed Answered

Publishing map to ArcGIS Server (10.6+) with Python - Conundrum!

Question asked by agelfert on Feb 4, 2019
Latest reply on Aug 15, 2019 by gnomic.admin

Hey all,

I'm caught in ESRI's library-name-change-and-circularly-referencing-documentation ****.

 

I have a number of MXD's that were the basis for a number ArcGIS map services in a 10.5.x standalone ArcGIS Server environment. I would like to publish these in a new federated ArcGIS Server environment (ArcGIS Enterprise).
How do I script that? Seems like that should be easy.

 

The older documentation suggests the following steps, which ring familiar... (CreateMapSDDraft—Help | ArcGIS Desktop )

arcpy.mapping.MapDocument( )
arcpy.mapping.CreateMapSDDraft( )
arcpy.StageService_server( )
arcpy.UploadServiceDefinition_server( )

But it turns out I don't have 'arcpy.mapping' module anymore.

AttributeError: module 'arcpy' has no attribute 'mapping'

Where did it go? It's been replaced with arc.mp. Huge semantic improvement!! But it's not like that's just a new name:

AttributeError: module 'arcpy.mp' has no attribute 'CreateMapSDDraft'

Well, publishing from MXD is no longer cool anyways. ESRI apparently wants you to live in the APRX world. So I "converted" an MXD to APRX to try another approach.


You'd think now you could use the following (CreateSharingDraft—Sharing module | ArcGIS Desktop ):

CreateSharingDraft - function
"The CreateSharingDraft function creates a MapServiceDraft from a Map in an ArcGIS Pro project that can be configured and shared to ArcGIS Server."

 

service_draft = arcpy.sharing.CreateSharingDraft( )
service_draft.exportToSDDraft( )
arcpy.StageService_server( )
arcpy.UploadServiceDefinition_server( )

No! 

AttributeError: module 'arcpy.sharing' has no attribute 'CreateSharingDraft'
What the heck???
sharing_draft = m.getWebLayerSharingDraft( )
sharing_draft.exportToSDDraft( )
arcpy.StageService_server( )
arcpy.UploadServiceDefinition_server( )

Using these steps, the code fails at

sharing_draft = m.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", service)
sharing_draft.exportToSDDraft(sddraft_output_filename)

ValueError: MAP_IMAGE

Is it possible that I've missed the one page in the documentation that makes sense? Please let me know. All I want to do is iterate over some directories with MXD files and publish them as map services.

UPDATE: I had a hunch that with multiple ESRI associated Python installs, one might offer the old arc.mapping. So looks like ArcMap's old Py2.7 still has it. Didn't think about that earlier because I'm working almost exclusively in Jupyter Notebook. Whether this is of much help, I don't know. Can't imagine going back and forth between releases.

 

Outcomes