Select to view content in your preferred language

Error when updating map while not logged in to ArcGIS Pro

922
7
01-06-2020 10:57 AM
KieranClark
Regular Contributor

I am receiving the following error when running a Python script to update a map for one of our Operations Dashboard:

C:\Users\kierc\projects\XXXXX XXXXXXX Extension Survey\Batch Files for Script Scheduling>"C:\ArcGIS_Pro\Conda\Cloned_Envs\arcgispro-py3-subtel\python.exe" "C:\Users\kierc\projects\api\UpdateXXXXXMap.py"
Creating SD file
Traceback (most recent call last):
  File "C:\Users\kierc\projects\api\UpdateXXXXXMap.py", line 33, in <module>
    arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS', True, True)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\mp.py", line 105, in CreateWebLayerSDDraft
    return _convertArcObjectToPythonObject(arcgisscripting._mapping.CreateWebLayerSDDraft(*_gp_fixargs([map_or_layers, out_sddraft, service_name, server_type, service_type, folder_name, overwrite_existing_service, copy_data_to_server, enable_editing, allow_exporting, enable_sync, summary, tags, description, credits, use_limitations], True)))
RuntimeError

I have X'd out the actual name of the files as there is some potentially sensitive information associated with the names, but the character counts and spacing are preserved.

Additionally, this is only an issue if I am logged out in ArcGIS Pro. However, logging in to ArcGIS Pro is not a full solution as I will need to be updating maps soon for multiple organizations. The following is the Python script I am using:

import arcpy
import os, sys
from arcgis.gis import GIS

### Start setting variables
# Set the path to the project
prjPath = r'C:\Users\kierc\Documents\ArcGIS\Projects\XXXXXXXXXXXExt\XXXXXXXXXXXExt.aprx'

# Update the following variables to match:
# Feature service/SD name in arcgis.com, user/password of the owner account
sd_fs_name = "XXXXX_XXXXXX_Extention_Inshore_Survey_WFL1"
portal = "http://www.arcgis.com" # Can also reference a local portal
user = "XXXXXXXXXXX"
password = "XXXXXXXXXXXXX"

# Set sharing options
shrOrg = False
shrEveryone = False
shrGroups = ""

### End setting variables

# Local paths to create temporary content
relPath = r'C:\Users\kierc\projects\api\arcgistempcurrent'
sddraft = os.path.join(relPath, "CurrentUpdate.sddraft")
sd = os.path.join(relPath, "CurrentUpdate.sd")

# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps()[0]
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS', True, True)
arcpy.StageService_server(sddraft, sd)

print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)

# Find the SD, update it, publish /w overwrite and set sharing and metadata
print("Search for original SD on portal…")
sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
print("Found SD: {}, ID: {} n Uploading and overwriting…".format(sdItem.title, sdItem.id))
sdItem.update(data=sd)
print("Overwriting existing feature service…")
fs = sdItem.publish(overwrite=True)

if shrOrg or shrEveryone or shrGroups:
  print("Setting sharing options…")
  fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)

print("Finished updating: {} – ID: {}".format(fs.title, fs.id))

Once again, specific filenames have been X'd out with number of characters and any spacing preserved. This script successfully updates the map as intended when logged in to ArcGIS Pro.

0 Kudos
7 Replies
JoeBorgione
MVP Emeritus

When you have a an ArcGIS Pro session open, you are consuming a license, so that's why your script works while you are logged in.  How are you managing your licenses?  Named users on AGOL or with a local license manager, or how?

That should just about do it....
0 Kudos
KieranClark
Regular Contributor

Hi Joe,

Thanks for responding. We had been using a Named User but have converted to a Single Use License. Each organization has a Creator, so I've been able to log in to different accounts to manage each organization's map items.

Is there a way to change things in the code to account for this?

0 Kudos
JoeBorgione
MVP Emeritus

Not sure how to do it exactly, but let me check a few things; my first thought is make sure what ever system user is running the script has access to the license.

That should just about do it....
0 Kudos
KieranClark
Regular Contributor

Not sure what you mean by that - do you mean Windows user?

0 Kudos
JoeBorgione
MVP Emeritus

If you are logged out of your computer, it sounds like you are running the script as a scheduled task: is that the case?  If so, what ever user executes the scheduled task need access to the license...

That should just about do it....
0 Kudos
KieranClark
Regular Contributor

Understood. I'm the only user on my computer and it is an administrator - the user stays logged in.

0 Kudos
JoeBorgione
MVP Emeritus

Hmmm.... that's weird... and the license is assigned to you...  I'd give tech support a call....

That should just about do it....
0 Kudos