Connecting ArcGIS Online to Online Notebook - SharePackage_management

252
1
12-05-2022 12:22 PM
CamiPawlak
New Contributor

Hi,

I am a new user to ArcGis Online Notebooks. I have a notebook in which I have created a tile package (.tpkx). 

I would like to use Share Package, to transfer the .tpkx from my files (/arcgis/home/) to My Content on ArcGIS Online. I think that Share Package is the way to do this, though if there is a better way I am eager to try anything out. 

I've been following this workflow so far, as my end goal is to create a tile service. However, when using Share Package, I get this error:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 002119: Must be connected and signed into the portal.
Failed to execute (SharePackage).

 

This is what I am running (but with my username and password):

arcpy.SharePackage_management("/arcgis/home/my_tile_package.tpkx", "username", "password",
"title", "tag1, tag2", "EVERYBODY") 

 

I've tried logging in as (again with my actual username) within the cell I am using share package in and in a separate cell:

import arcpy

from arcgis.gis import GIS
gis=GIS("https://arcgis.com", "my_username")

 

I am running all of this in an advanced notebook. I know the error has to do with not correctly connecting Arc Online and the notebook somehow, but I can't seem to figure out how to do it the right way. 

I appreciate any help and advice!

 

0 Kudos
1 Reply
CamiPawlak
New Contributor

In case anyone stumble on this, the solution was to use this in the cell before sharepackage:

#Code Snippet to Sign in to Portal for ArcPy

import arcpy # arcpy requires advanced notebook runtime
from datetime import datetime

def arcpy_SignInToPortal(gis_url: str, user: str, pwd: str) -> None:
signed_in = arcpy.SignInToPortal(gis_url, user, pwd)
expires = signed_in.get("expires")
expire_time = datetime.fromtimestamp(expires)
current_time = datetime.now()
print(f"ArcPy is signed in to {gis_url}. \nThe token is expiring at {expire_time}. \nThe current time is {current_time}.")

arcpy_SignInToPortal('https://DOMAIN.maps.arcgis.com/', 'USERNAME', 'PASSWORD')

0 Kudos