<?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 Obscure password in a script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/129157#M10026</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to automate a process of checking to see if my server services are running every morning. I'm following &lt;A href="https://enterprise.arcgis.com/en/server/latest/administer/linux/example-check-a-folder-for-stopped-services.htm"&gt;this example script&lt;/A&gt;, but I need to store my credentials in the script as I will be running it in the early morning hours and will not be sitting there to input my credentials every time it runs. Hard-coding my username and password into the script seems like a bad idea since it will be connecting to the internet by making web requests, so how do&amp;nbsp;I go about obscuring or encrypting it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will be a standalone python script run using windows task scheduler. Working with ArcMap and Enterprise 10.7, python 2.7.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 May 2020 13:15:59 GMT</pubDate>
    <dc:creator>MKF62</dc:creator>
    <dc:date>2020-05-28T13:15:59Z</dc:date>
    <item>
      <title>Obscure password in a script</title>
      <link>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/129157#M10026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to automate a process of checking to see if my server services are running every morning. I'm following &lt;A href="https://enterprise.arcgis.com/en/server/latest/administer/linux/example-check-a-folder-for-stopped-services.htm"&gt;this example script&lt;/A&gt;, but I need to store my credentials in the script as I will be running it in the early morning hours and will not be sitting there to input my credentials every time it runs. Hard-coding my username and password into the script seems like a bad idea since it will be connecting to the internet by making web requests, so how do&amp;nbsp;I go about obscuring or encrypting it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will be a standalone python script run using windows task scheduler. Working with ArcMap and Enterprise 10.7, python 2.7.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2020 13:15:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/129157#M10026</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2020-05-28T13:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Obscure password in a script</title>
      <link>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/129158#M10027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Basically the same question was asked a couple weeks ago, see &lt;A href="https://community.esri.com/thread/253235-save-portal-password-securely"&gt;https://community.esri.com/thread/253235-save-portal-password-securely&lt;/A&gt; .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2020 13:30:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/129158#M10027</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-05-28T13:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Obscure password in a script</title>
      <link>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/129159#M10028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I was able to implement two solutions and both work equally well. I went with keyring because it seems more secure than just creating a separate python module to import into the script to get the username/password from. I'll document exactly what I did for the sake of clarity when others come across this question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Option #1: Create a separate python module&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Basically, you have two scripts. One .py file with your code doing whatever you want upon login, the other .py file with your username and password:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;#credentials.py&lt;/SPAN&gt;

username &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MyUserName
password &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MyPassword&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then import that module into your code that's running whatever you want:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; credentials &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; username&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; password

&lt;SPAN class="comment token"&gt;#Log into whatever with username and password variables to do stuff&lt;/SPAN&gt;
‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Option #2: Use keyring&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Pip install keyring into the ArcGIS python interpreter. Open Credentials Manager (windows) on your computer from the control panel. Go to Windows Credentials &amp;gt; Add Generic Credential. Fill out the internet or network address with any name (you'll reference it as a service name in your python script). Fill out the username and password with the appropriate credentials for whatever application you want your python script to login to. In your python script that utilizes these credentials:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; keyring

&lt;SPAN class="comment token"&gt;#The username should be what you entered as a username in the credentials manager&lt;/SPAN&gt;
username &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'MyUserName'&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#The first argument is whatever you entered as the internet/network address in credentials manager&lt;/SPAN&gt;
password &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; keyring&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;get_password&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'AGSServicesStatus'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; username&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:17:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/129159#M10028</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2021-12-11T07:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Obscure password in a script</title>
      <link>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/1115418#M62938</link>
      <description>&lt;P&gt;Hi All - I found that a previous version of keyring is already installed in&amp;nbsp;Pro (see pic).&amp;nbsp; Is it necessary to Pip install keyring if Pro is available on the machine where the script will be executed?&amp;nbsp; &amp;nbsp;I tried cloning the environment, but couldn't update the keyring version (will come back to that).&amp;nbsp; Anyway, for simplicity sake (apart from the version) is there an issue with using this already-available package?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NickHarvey_2-1636491546278.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27092iAD0B036C00397271/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NickHarvey_2-1636491546278.png" alt="NickHarvey_2-1636491546278.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 21:07:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/obscure-password-in-a-script/m-p/1115418#M62938</guid>
      <dc:creator>NickHarvey</dc:creator>
      <dc:date>2021-11-09T21:07:10Z</dc:date>
    </item>
  </channel>
</rss>

