<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic replace Username/Password with SDE connection in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1285359#M8647</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently doing the below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from arcgis.gis import GIS
import arcgis
gis = GIS('https://xxxx.maps.arcgis.com', agol_username, agol_password)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I do not want to hard code the Username and Password in the script&lt;/P&gt;&lt;P&gt;Can I do something like point to an SDE connection?&lt;/P&gt;&lt;P&gt;I want a way to HIDE the credentials&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from arcgis.gis import GIS
import arcgis
gis = GIS('https://xxxx.maps.arcgis.com', '\\DatabaseConnections\conectionfile.sde)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or add in a workspace for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.env.workspace = "C:\\Users\\GIS_projects\\Python\\Test@EDIT.sde"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 May 2023 18:36:12 GMT</pubDate>
    <dc:creator>kapalczynski</dc:creator>
    <dc:date>2023-05-03T18:36:12Z</dc:date>
    <item>
      <title>replace Username/Password with SDE connection</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1285359#M8647</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently doing the below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from arcgis.gis import GIS
import arcgis
gis = GIS('https://xxxx.maps.arcgis.com', agol_username, agol_password)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I do not want to hard code the Username and Password in the script&lt;/P&gt;&lt;P&gt;Can I do something like point to an SDE connection?&lt;/P&gt;&lt;P&gt;I want a way to HIDE the credentials&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from arcgis.gis import GIS
import arcgis
gis = GIS('https://xxxx.maps.arcgis.com', '\\DatabaseConnections\conectionfile.sde)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or add in a workspace for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.env.workspace = "C:\\Users\\GIS_projects\\Python\\Test@EDIT.sde"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 18:36:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1285359#M8647</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-05-03T18:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: replace Username/Password with SDE connection</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1285380#M8648</link>
      <description>&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;gis = GIS("home")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will run using the credentials of the last user to log into Pro under that profile.&lt;/P&gt;&lt;P&gt;I actually have a scheduled task that opens Pro and closes it every 10 days just to keep the credentials "active".&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 19:17:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1285380#M8648</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-05-03T19:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: replace Username/Password with SDE connection</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1285391#M8649</link>
      <description>&lt;P&gt;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&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 19:36:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1285391#M8649</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-05-03T19:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: replace Username/Password with SDE connection</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1295233#M8752</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp; I piecemeal solutions from different sources; you might want to check them out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-protect-credentials-by-storing-them/m-p/810024#M2424" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-protect-credentials-by-storing-them/m-p/810024#M2424&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I also would like to add that to set a password using keyring I ran Python Interactive Terminal (C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat) and followed the instructions on this video&amp;nbsp;&lt;A href="https://www.youtube.com/watch?v=lLMhq3c_YQk" target="_blank" rel="noopener"&gt;https://www.youtube.com/watch?v=lLMhq3c_YQk.&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This is what I came up with:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 00:44:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/replace-username-password-with-sde-connection/m-p/1295233#M8752</guid>
      <dc:creator>Jen_Zumbado-Hannibal</dc:creator>
      <dc:date>2023-06-02T00:44:05Z</dc:date>
    </item>
  </channel>
</rss>

