<?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 Re: Unable to access token using gis._con.token in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1483700#M10105</link>
    <description>&lt;P&gt;Looks like this is still an issue in ArcGIS Pro 3.3./Python API 2.3.0. If arcpy is available,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/580505"&gt;@Vincentvd&lt;/a&gt;'s solution works, but we had a need to find a workaround when arcpy wasn't available.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've had success using the authenticated session object for REST API and Sharing API calls to secured services instead of passing the token explicitly, like so (only tested on AGOL):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import json
from arcgis.gis import GIS

gis = GIS("pro")

# Use the session from the GIS object
session = gis._con._session

# Example secured URL, doesn't have to be admin, just an example
update_definition_url = "https://services8.arcgis.com/XXXXXXXXXXXXXXXX/arcgis/rest/admin/services/XXXXXXXXXXX/FeatureServer/updateDefinition"

# Define some parameters for the update; again, just an example
update_def_params = {
    'updateDefinition': json.dumps({
        "capabilities": "Query,Editing,Create,Update,Delete,Sync"
    }),
    'async': 'false',
    'f': 'json'
}

response = session.post(update_definition_url, data=update_def_params, timeout=10)
result = response.json()
print(result)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This apparently provides a subclass of a Requests session, so you can use it in place of requests; e.g., session.get, session.post, etc. Your mileage may vary, but this solved the problem for me in a workflow where arcpy wasn't an option.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jun 2024 03:13:57 GMT</pubDate>
    <dc:creator>JRhodes</dc:creator>
    <dc:date>2024-06-04T03:13:57Z</dc:date>
    <item>
      <title>Unable to access token using gis._con.token</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1353899#M9332</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I'm hoping someone can help with this problem I ran into today. I can no longer access the authentication token using the Connect through Built-In account method, or the Connect through Pro method. Both of these methods worked for me up until today, and would return a token string accessed through gis._con.token. I can still get a token through OAuth, but I need to run scheduled scripts, unsupervised. Also, my org doesn't use Named User Authentication, so username/password isn't an option.&lt;BR /&gt;&lt;BR /&gt;// This method still works, and returns a token:&lt;/P&gt;&lt;P&gt;gis = GIS('https:myGisPortal.maps.arcgis.com', client_id='myClientID')&lt;BR /&gt;print("Logged in as: " + gis.properties.user.username)&lt;BR /&gt;print('token='+str(gis._con.token))&lt;/P&gt;&lt;P&gt;Returns:&lt;BR /&gt;Logged in as: myUsername&lt;BR /&gt;token=sYzv_5rgSSiElv7...bzoR2oayAHTvuJG8&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// But these methods don't work anymore, and do not return a token:&lt;/P&gt;&lt;P&gt;gis = GIS('pro')&lt;BR /&gt;print("Logged in as: " + gis.properties.user.username)&lt;BR /&gt;print('token='+str(gis._con.token))&lt;/P&gt;&lt;P&gt;Returns:&lt;BR /&gt;Logged in as: myUsername&lt;BR /&gt;token=None&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;gis = GIS('home')&lt;BR /&gt;print("Logged in as: " + gis.properties.user.username)&lt;BR /&gt;print('token='+str(gis._con.token))&lt;/P&gt;&lt;P&gt;Returns:&lt;BR /&gt;Logged in as: myUsername&lt;BR /&gt;token=None&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 01:31:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1353899#M9332</guid>
      <dc:creator>DCWORK_GIS</dc:creator>
      <dc:date>2023-11-28T01:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to access token using gis._con.token</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1354746#M9338</link>
      <description>&lt;P&gt;To add context, I recently upgraded from AG Pro 2.9 to 3.2. Both authentication methods &lt;SPAN&gt;&lt;STRONG&gt;gis = GIS('home')&lt;/STRONG&gt; &amp;amp;&amp;nbsp;&lt;STRONG&gt;gis = GIS('pro')&lt;/STRONG&gt;&amp;nbsp; would allow access to the authentication token through&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;token=gis._con.token&lt;/STRONG&gt;&amp;nbsp;in AG Pro 2.9, but this does not seem to be the case anymore in 3.x. 2 coworkers tested it in their 3.2 machines and it didn't work for them, and one tested it in 3.1.2, and it didn't work there either.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2023 18:00:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1354746#M9338</guid>
      <dc:creator>DCWORK_GIS</dc:creator>
      <dc:date>2023-11-29T18:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to access token using gis._con.token</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1359320#M9401</link>
      <description>&lt;P&gt;I have the same problem.&amp;nbsp; To clarify, I am attempting to pass Active Directory credentials to GIS() to our enterprise portal.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gis = GIS('https://portalserver.domain.com/arcgis', 'Domain\\username', 'myPassword')&lt;/LI-CODE&gt;&lt;P&gt;I know the authentication is succeeding because if I intentionally fudge the password the script fails.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2023 19:48:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1359320#M9401</guid>
      <dc:creator>ChrisDalla_Piazza</dc:creator>
      <dc:date>2023-12-11T19:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to access token using gis._con.token</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1412267#M9903</link>
      <description>&lt;P&gt;Faced the same problem today with GIS("PRO"). The solution when using arcgis pro seems to be using the following code. I also tested GIS() with a URL to arcgis enterprise with a username and password and that also works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

token = arcpy.GetSigninToken()
if token is not None:
    print(token['token'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Source:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/getsignintoken.htm" target="_blank" rel="noopener"&gt;GetSigninToken—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 14:16:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1412267#M9903</guid>
      <dc:creator>Vincentvd</dc:creator>
      <dc:date>2024-04-19T14:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to access token using gis._con.token</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1483700#M10105</link>
      <description>&lt;P&gt;Looks like this is still an issue in ArcGIS Pro 3.3./Python API 2.3.0. If arcpy is available,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/580505"&gt;@Vincentvd&lt;/a&gt;'s solution works, but we had a need to find a workaround when arcpy wasn't available.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've had success using the authenticated session object for REST API and Sharing API calls to secured services instead of passing the token explicitly, like so (only tested on AGOL):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import json
from arcgis.gis import GIS

gis = GIS("pro")

# Use the session from the GIS object
session = gis._con._session

# Example secured URL, doesn't have to be admin, just an example
update_definition_url = "https://services8.arcgis.com/XXXXXXXXXXXXXXXX/arcgis/rest/admin/services/XXXXXXXXXXX/FeatureServer/updateDefinition"

# Define some parameters for the update; again, just an example
update_def_params = {
    'updateDefinition': json.dumps({
        "capabilities": "Query,Editing,Create,Update,Delete,Sync"
    }),
    'async': 'false',
    'f': 'json'
}

response = session.post(update_definition_url, data=update_def_params, timeout=10)
result = response.json()
print(result)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This apparently provides a subclass of a Requests session, so you can use it in place of requests; e.g., session.get, session.post, etc. Your mileage may vary, but this solved the problem for me in a workflow where arcpy wasn't an option.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 03:13:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1483700#M10105</guid>
      <dc:creator>JRhodes</dc:creator>
      <dc:date>2024-06-04T03:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to access token using gis._con.token</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1483735#M10106</link>
      <description>&lt;P&gt;I haven't tested yet but this looks promising. The ArcPy solution is good too, but if you want to use arcPy in a Notebook on AGOL you have to pay extra. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 23:31:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-access-token-using-gis-con-token/m-p/1483735#M10106</guid>
      <dc:creator>DCWORK_GIS</dc:creator>
      <dc:date>2024-06-03T23:31:22Z</dc:date>
    </item>
  </channel>
</rss>

