Publish a Web tools

538
1
02-22-2019 03:49 PM
DamasoAvalos_Ruiz1
New Contributor III

Hello,

 

I am writing to request technical assistance. I created a python script that needs to execute the following, in the indicated order:

 

1) generate some rasters,

2) add the rasters to a map

3) publish the map as a MAP_IMAGE to an ArcGIS Server federated with a Portal.

 

I published the python script to ArcGis Server as a Web Tool, so I can later use it from a web app as a REST Service.

The problem I am experiencing is: Once the webtool is created and I try to execute it as a rest service from the browser I get errors. Please see below for Code Version 1 and its errors and Code Version 2 and its errors;

Version 1

Code:

    # ## Version 1 - Using map.getWebLayerSharingDraft

    sharing_draft = _work_map.getWebLayerSharingDraft('FEDERATED_SERVER', 'MAP_IMAGE', service)

    sharing_draft.federatedServerUrl = str(svr_fed)

    sharing_draft.summary = _work_map.name

    sharing_draft.tags = _work_map.name

    sharing_draft.description = 'Create Rasters'

    sharing_draft.credits = 'Create Rasters'

    sharing_draft.useLimitations = 'My Use Limitations'

    sharing_draft.copyDataToServer = True

    sharing_draft.offline = False

    sharing_draft.overwriteExistingService = True

    # ## End Version 1

Error:

'Map' object has no attribute 'getWebLayerSharingDraft'

 

Version 2

Code:

    # ## Version 2 - Using arcpy.sharing.CreateSharingDraft

    sharing_draft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "MAP_SERVICE", service, _work_map)

    sharing_draft.targetServer = svr_fed

    sharing_draft.summary = _work_map.name

    sharing_draft.tags = _work_map.name

    sharing_draft.description = 'Create Rasters'

    sharing_draft.credits = 'Create Rasters'

    sharing_draft.useLimitations = 'My Use Limitations'

    sharing_draft.copyDataToServer = True

    sharing_draft.offline = True

    sharing_draft.overwriteExistingService = True

    # ## End Version 2

Error:

module 'arcpy' has no attribute 'sharing'

 

 Both versions run perfectly in ArcGis Pro

ArcGIS version: Pro 2.3.0, Python version: 3.6.6

Python version on ArcGis Server: 2.7

 

Some Links consulted;

https://pro.arcgis.com/en/pro-app/arcpy/sharing/mapimagesharingdraft-class.htm

https://pro.arcgis.com/en/pro-app/arcpy/sharing/mapservicedraft-class.htm

https://community.esri.com/thread/223789-getweblayersharingdraft-not-found

 

 

thank you

0 Kudos
1 Reply
Nicole_Ueberschär
Esri Regular Contributor

My guess is (I had a similar experience with other modules from arcpy) that the modules are called slightly differently in Python 3 compared to Python 2.7. If you can, I would suggest to add the python 3 to your server. If it is a Linux, this document might help: Python 3 runtime for ArcGIS Server on Linux—ArcGIS Server Administration (Linux) | Documentation for... 

To test it you could run it in ArcMap (if you have that available) which uses 2.7

The arcpy.sharing module was introduced at ArcGIS Pro 2.2 to provide a better experience when sharing web layers over the previously existing function CreateWebLayerSDDraft. The original function is provided only for backward compatibility.

so I assume, this is a new module and not yet available in 2.7 which would explain the error for option 2.

For option 1 I know that the schema of the map project - map - layer is very different compared to mxd - dataframe - layer so this is also related to Python 2.7 vs 3 I'm afraid. 

I hope this helps.