I am currently doing the below
from arcgis.gis import GIS
import arcgis
gis = GIS('https://xxxx.maps.arcgis.com', agol_username, agol_password)
But I do not want to hard code the Username and Password in the script
Can I do something like point to an SDE connection?
I want a way to HIDE the credentials
from arcgis.gis import GIS
import arcgis
gis = GIS('https://xxxx.maps.arcgis.com', '\\DatabaseConnections\conectionfile.sde)
Or add in a workspace for this?
arcpy.env.workspace = "C:\\Users\\GIS_projects\\Python\\Test@EDIT.sde"
One way, If you are running on a machine with Pro installed, and have logged into Pro within the last two weeks with the user credential that you want to pass, you can use:
gis = GIS("home")
This will run using the credentials of the last user to log into Pro under that profile.
I actually have a scheduled task that opens Pro and closes it every 10 days just to keep the credentials "active".
R_
Its on a server and no real direct access to remote on... so not sure of who credentials will be sitting there when I looks
@kapalczynski I piecemeal solutions from different sources; you might want to check them out.
This is what I came up with:
import keyring
from arcgis.gis import GIS
from arcgis.gis.server import Server
# Specify the name of the profile
profile_name = "GIS_Admin" # Replace with your profile name
# Get username and password stored in keyring
credentials = keyring.get_credential("keyring_portaladmin", username=None)
vusername = credentials.username
vpassword = credentials.password
# Connect to the ArcGIS Portal using the specified profile
gis = GIS(url="https://your.domain.com", username=vusername, password=vpassword,profile=profile_name)
# Check if the connection is successful
if gis:
print("Connected to ArcGIS Portal as '{}'.".format(gis.properties.user.username))
else:
print("Failed to connect to ArcGIS Portal.")