<?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 Login into Portal with Token in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1566925#M73639</link>
    <description>&lt;P&gt;I am trying to use this example and it does not work...&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/signintoportal.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/signintoportal.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The last line Fails :&amp;nbsp; The example dosent have the appropriate number of arguments... If I remove one of them it then asks for the Password...&amp;nbsp;&lt;/P&gt;&lt;P&gt;resp = arcpy.SignInToPortal(portal_url, token=token, token_referer=portal_url, token_expiry=token_expiry)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 2494, in SignInToPortal&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;return _SignInToPortal(*args, **kwargs)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;TypeError: SignInToPortal() takes at most 3 arguments (4 given)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Yet the documentation shows many more arguments&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;SignInToPortal (portal_url, {username}, {password}, {cert_file}, {key_file}, {token}, {token_referer}, {token_expiry})&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It appears ESRI documentation is wrong ... whats the correct way to use a TOKEN instead of username and password&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
import requests

# assemble arguments into a dictionary
# for additional help on the generateToken REST service, see your portal documentation
portal_url = "https://example.com/portal/"
gen_token_url = f"{portal_url}sharing/rest/generateToken"
params = {"f": "json",               # Response format
		  "username": "username",    # Your ArcGIS Portal username
		  "password": "password",    # Your ArcGIS Portal password
		  "referer": gen_token_url,  # URL of the referring application (usually your portal)
		  "expiration": 60           # Token expiration time in minutes (default: 60)
 		}

# get a token using python's requests module
resp = requests.post(gen_token_url, data=params)

# check response. If failed, show response.text
assert resp.status_code == 200, resp.text

# now use token with SignInToPortal
token = resp.json()['token']
token_expiry = int(resp.json()['expires']/1000)  # convert to seconds since generateToken returns milliseconds
resp = arcpy.SignInToPortal(portal_url, token=token, token_referer=portal_url, token_expiry=token_expiry)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THe&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2024 19:24:17 GMT</pubDate>
    <dc:creator>kapalczynski</dc:creator>
    <dc:date>2024-12-10T19:24:17Z</dc:date>
    <item>
      <title>Login into Portal with Token</title>
      <link>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1566925#M73639</link>
      <description>&lt;P&gt;I am trying to use this example and it does not work...&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/signintoportal.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/signintoportal.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The last line Fails :&amp;nbsp; The example dosent have the appropriate number of arguments... If I remove one of them it then asks for the Password...&amp;nbsp;&lt;/P&gt;&lt;P&gt;resp = arcpy.SignInToPortal(portal_url, token=token, token_referer=portal_url, token_expiry=token_expiry)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 2494, in SignInToPortal&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;return _SignInToPortal(*args, **kwargs)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;TypeError: SignInToPortal() takes at most 3 arguments (4 given)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Yet the documentation shows many more arguments&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;SignInToPortal (portal_url, {username}, {password}, {cert_file}, {key_file}, {token}, {token_referer}, {token_expiry})&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It appears ESRI documentation is wrong ... whats the correct way to use a TOKEN instead of username and password&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
import requests

# assemble arguments into a dictionary
# for additional help on the generateToken REST service, see your portal documentation
portal_url = "https://example.com/portal/"
gen_token_url = f"{portal_url}sharing/rest/generateToken"
params = {"f": "json",               # Response format
		  "username": "username",    # Your ArcGIS Portal username
		  "password": "password",    # Your ArcGIS Portal password
		  "referer": gen_token_url,  # URL of the referring application (usually your portal)
		  "expiration": 60           # Token expiration time in minutes (default: 60)
 		}

# get a token using python's requests module
resp = requests.post(gen_token_url, data=params)

# check response. If failed, show response.text
assert resp.status_code == 200, resp.text

# now use token with SignInToPortal
token = resp.json()['token']
token_expiry = int(resp.json()['expires']/1000)  # convert to seconds since generateToken returns milliseconds
resp = arcpy.SignInToPortal(portal_url, token=token, token_referer=portal_url, token_expiry=token_expiry)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THe&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 19:24:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1566925#M73639</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-12-10T19:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Login into Portal with Token</title>
      <link>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1566956#M73640</link>
      <description>&lt;P&gt;I think this method only had 3 arguments before 3.x of ArcGIS Pro.&amp;nbsp; If you're on 2.x Pro that would make sense.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 20:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1566956#M73640</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2024-12-10T20:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Login into Portal with Token</title>
      <link>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1567041#M73641</link>
      <description>&lt;P&gt;Im running it with arcpy 3.7.11&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_0-1733868593884.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/121369i6440870A94ABBB81/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kapalczynski_0-1733868593884.png" alt="kapalczynski_0-1733868593884.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 22:10:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1567041#M73641</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-12-10T22:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Login into Portal with Token</title>
      <link>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1567055#M73642</link>
      <description>&lt;P&gt;Ok then that's a 2.9 ArcGIS Pro install.&amp;nbsp; Your arcpy version would be 2.9, the 3.7.11 refers to the Python version.&lt;BR /&gt;&lt;BR /&gt;2.9 ArcGIS Pro archived help shows only the 3 arguments available unfortunately&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.9/arcpy/functions/signintoportal.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/2.9/arcpy/functions/signintoportal.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 22:22:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/login-into-portal-with-token/m-p/1567055#M73642</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2024-12-10T22:22:48Z</dc:date>
    </item>
  </channel>
</rss>

