<?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: Create token and access feature Layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705565#M75270</link>
    <description>&lt;P&gt;Yea I had that originally and it did not work... was getting errors... google suggested the way I am doing it now.&lt;/P&gt;&lt;P&gt;I am going to test again and see what error it is throwing...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_0-1780359674724.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/153300i3DD88C79BBF3CD18/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kapalczynski_0-1780359674724.png" alt="kapalczynski_0-1780359674724.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jun 2026 00:21:53 GMT</pubDate>
    <dc:creator>kapalczynski</dc:creator>
    <dc:date>2026-06-02T00:21:53Z</dc:date>
    <item>
      <title>Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705540#M75267</link>
      <description>&lt;P&gt;I have this code snip below.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Trying to get a token&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;return that token&lt;/LI&gt;&lt;LI&gt;and use&amp;nbsp;gis.content.get(feature_layer_id) to secure access to a service&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Line 14 The variable "custom_token" prints with no issues&lt;/LI&gt;&lt;LI&gt;Line 18 prints fine as well "Token successfully generated! Expires at timestamp: 1780364453189"&lt;/LI&gt;&lt;LI&gt;Line 21 prints back NONE&lt;/LI&gt;&lt;LI&gt;and Line 23 gives error:&amp;nbsp;Exception: You do not have permissions to access this resource or perform this operation.&lt;BR /&gt;(Error Code: 403)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The user Name and password are owner level permissions and have access to everything in our Enterprise... so im confused.&lt;/P&gt;&lt;P&gt;AND confused why line 21 returns NONE&lt;/P&gt;&lt;P&gt;The reson I am going this route is I need to increase the token expiration time... not sure how to do it any other way...&amp;nbsp;&lt;/P&gt;&lt;P&gt;otherwise I would just do this&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if portal_username == '' and portal_password == '':
    gis = GIS(profile='Survey123_prof')
else:
    gis = GIS(portal_url, portal_username, portal_password)
    
token = gis._con.token
item_object = gis.content.get(feature_layer_id)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ANY thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;token_url = f"{portal_url}/sharing/rest/generateToken"
payload = {
    "username": portal_username,
    "password": portal_password,
    "client": "referer",
    "referer": portal_url,
    "expiration": expiration_minutes,
    "f": "json"
}

response = requests.post(token_url, data=payload)
token_data = response.json()
custom_token = token_data["token"]
print("custom token " + custom_token)

gis = GIS(url=portal_url, credentials={"token": custom_token})

print(f"Token successfully generated! Expires at timestamp: {token_data['expires']}")

tokenvalue = gis._con.token
print(tokenvalue)

item_object = gis.content.get(feature_layer_id)
print(item_object)&lt;/LI-CODE&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>Mon, 01 Jun 2026 19:49:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705540#M75267</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-01T19:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705557#M75268</link>
      <description>&lt;P&gt;definitely has to do with permissions...&lt;/P&gt;&lt;P&gt;The username and password credentials I am using.... I tool that user and added it to a group and assigned the group to that Service and still did not work...&amp;nbsp;&lt;/P&gt;&lt;P&gt;once I made public it worked...&amp;nbsp; not sure why it has to be public if I have it shared to the Organization and I have a group with that user in it...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2026 22:36:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705557#M75268</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-01T22:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705561#M75269</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think this may be the way you're adding the token in, from the documentation here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html" target="_blank"&gt;https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It's showing that the way to use the token is like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gis = GIS(url=portal_url, token="token_if_string")&lt;/LI-CODE&gt;&lt;P&gt;Just make sure if it's just a plain copy paste string then to surround with quotes, otherwise calling the variable should work just fine with token=token_var etc.&lt;/P&gt;&lt;P&gt;Let me know if this ends up getting you farther!&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2026 23:38:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705561#M75269</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2026-06-01T23:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705565#M75270</link>
      <description>&lt;P&gt;Yea I had that originally and it did not work... was getting errors... google suggested the way I am doing it now.&lt;/P&gt;&lt;P&gt;I am going to test again and see what error it is throwing...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_0-1780359674724.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/153300i3DD88C79BBF3CD18/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kapalczynski_0-1780359674724.png" alt="kapalczynski_0-1780359674724.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2026 00:21:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705565#M75270</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-02T00:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705566#M75271</link>
      <description>&lt;P&gt;Line 14 prints the token I am receiving...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line 16 seems to fail :&amp;nbsp;gis = GIS(url=portal_url, token=custom_token)&lt;/P&gt;&lt;P&gt;BUT you can see from the error that the correct token is being printed... its a valid token&lt;/P&gt;&lt;P&gt;custom token xQiM4Ft72qRDLEmW9BOTojBmvVMHp2YGEwBXTyIHrf3eYJLpV9NrTUV2y_XzKBdsRaiME2Rc5UUmnMQYW3dv-aTOBSmb_GdLWMyguTSZyfAMn1d-LayS1w......................................c1rulv6_dMf0XW4qhLi2g..&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "C:\Users\xyzx\Desktop\~GIS_projects\~xyzx\~AttachmentsNotVisible_Processing\script.py", line 72, in &amp;lt;module&amp;gt;&lt;BR /&gt;gis = GIS(url=portal_url, token=custom_token)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 550, in __init__&lt;BR /&gt;self._portal.get_properties(force=force_refresh)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_portalpy.py", line 1227, in get_properties&lt;BR /&gt;raise e&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_portalpy.py", line 1207, in get_properties&lt;BR /&gt;resp = self.con.post(path, self._postdata(), ssl=True)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1079, in post&lt;BR /&gt;force_bytes=kwargs.pop("force_bytes", False),&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 625, in _handle_response&lt;BR /&gt;self._handle_json_error(data["error"], errorcode)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 648, in _handle_json_error&lt;BR /&gt;raise Exception(errormessage)&lt;BR /&gt;Exception: Invalid token.&lt;BR /&gt;(Error Code: 498)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;token_url = f"{portal_url}/sharing/rest/generateToken"
payload = {
    "username": portal_username,
    "password": portal_password,
    "client": "referer",
    "referer": portal_url,
    "expiration": expiration_minutes,
    "f": "json"
}

response = requests.post(token_url, data=payload)
token_data = response.json()
custom_token = token_data["token"]
print("custom token " + custom_token)

gis = GIS(url=portal_url, token=custom_token)

print(f"Token successfully generated! Expires at timestamp: {token_data['expires']}")

tokenvalue = gis._con.token
print(tokenvalue)

token = custom_token
print(tokenvalue)

item_object = gis.content.get(feature_layer_id)
print(item_object)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2026 00:30:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705566#M75271</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-02T00:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705567#M75272</link>
      <description>&lt;P&gt;This works but the token does not stay alive long enough for me to run the script...&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if portal_username == '' and portal_password == '':
gis = GIS(profile='Survey123_prof')
else:
gis = GIS(portal_url, portal_username, portal_password)

token = gis._con.token
item_object = gis.content.get(feature_layer_id)

print(token)
print(item_object)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 02 Jun 2026 00:38:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705567#M75272</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-02T00:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705568#M75273</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in this case, I'm wondering if it's binding the referrer token to a URL that you're not meaning to use or the code is misinterpreting.&lt;/P&gt;&lt;P&gt;I personally would do some debugging prints, and check to see if anything pops up that isn't intended:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print("Portal: ", portal_url)
print("Referer: ", payload.get("referer"))
print("GIS Referrer: ", getattr(gis, '_referer', 'Not set'))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does your portal URL end with /portal or just &lt;A href="https://community.esri.com/" target="_blank"&gt;https://&amp;lt;fqdn&amp;gt;.com/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2026 00:47:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705568#M75273</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2026-06-02T00:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705569#M75274</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't end up seeing the reply where you mentioned that the token doesn't stay alive long enough my apologies.&lt;/P&gt;&lt;P&gt;You had send an older expiry time, this one here&amp;nbsp;1780364453189 and it shows that it should expire June 02 GMT so it should be well old enough. Still I'd check your max token lifetime in the portal admin, then Portals &amp;gt; Self, and check the maxTokenExpirationMinutes, maybe temporarily set to 10080 for 7 days or more, then Update Organization.&lt;/P&gt;&lt;P&gt;Along with this, inside of your code, if it's super long running, you may put a token refresh function in that just recalls a new token, and adds the newer token to the gis object.&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2026 00:52:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705569#M75274</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2026-06-02T00:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705669#M75277</link>
      <description>&lt;P&gt;I have run into token issues like this with portal in the past. Below is the basic method that has worked for me. .&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gis = GIS("https://xyz:7443/arcgis", "xxUNxx", "xxPWxx", verify_cert=False)
token = gis.session.auth.token
auth_info = (gis.session.auth)&lt;/LI-CODE&gt;&lt;P&gt;After this, I place the token in a dictionary {"token": token}, then store it in a csv for other scripts to access or&amp;nbsp; just use it in my active python requests. Good luck. I know this issue can be frustrating.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2026 15:46:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705669#M75277</guid>
      <dc:creator>BrianLomas</dc:creator>
      <dc:date>2026-06-02T15:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705917#M75280</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/105904"&gt;@BrianLomas&lt;/a&gt;&amp;nbsp; doesn't the token expire on you though&lt;/P&gt;&lt;P&gt;I am not sure what this is and how that would play into my script.... how would that work with the simple example below&lt;BR /&gt;Or the more elaborate one in this post...&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if portal_username == '' and portal_password == '':
    gis = GIS(profile='Survey123_prof')
else:
    gis = GIS(portal_url, portal_username, portal_password)
    
token = gis._con.token
item_object = gis.content.get(feature_layer_id)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or the more elaborate one below...&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;token_url = f"{portal_url}/sharing/rest/generateToken"
payload = {
    "username": portal_username,
    "password": portal_password,
    "client": "referer",
    "referer": portal_url,
    "expiration": expiration_minutes,
    "f": "json"
}

response = requests.post(token_url, data=payload)
token_data = response.json()
custom_token = token_data["token"]

print("custom token " + custom_token)

#gis = GIS(url=portal_url, token=custom_token)
gis = GIS(url=portal_url, credentials={"token": custom_token})

print(f"Token successfully generated! Expires at timestamp: {token_data['expires']}")

print("Portal: ", portal_url)
print("Referer: ", payload.get("referer"))
print("GIS Referrer: ", getattr(gis, '_referer', 'Not set'))

tokenvalue = gis._con.token
print(tokenvalue)

token = custom_token
print(tokenvalue)

item_object = gis.content.get(feature_layer_id)
print(item_object)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 13:57:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705917#M75280</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-03T13:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705920#M75281</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/712076"&gt;@CodyPatterson&lt;/a&gt;&amp;nbsp; OK I will do some of that debugging and see...&amp;nbsp;&lt;BR /&gt;My URL ends with /portal&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;A href="https://xyzxyz.xyzx.xyzxyz.gov/portal" target="_blank"&gt;https://xyzxyz.xyzx.xyzxyz.gov/portal&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 13:38:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705920#M75281</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-03T13:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705923#M75282</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code and Return&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;token_url = f"{portal_url}/sharing/rest/generateToken"
payload = {
    "username": portal_username,
    "password": portal_password,
    "client": "referer",
    "referer": portal_url,
    "expiration": expiration_minutes,
    "f": "json"
}

response = requests.post(token_url, data=payload)
token_data = response.json()
custom_token = token_data["token"]

print("custom token " + custom_token)

#gis = GIS(url=portal_url, token=custom_token)
gis = GIS(url=portal_url, credentials={"token": custom_token})

print(f"Token successfully generated! Expires at timestamp: {token_data['expires']}")

print("Portal: ", portal_url)
print("Referer: ", payload.get("referer"))
print("GIS Referrer: ", getattr(gis, '_referer', 'Not set'))

tokenvalue = gis._con.token
print(tokenvalue)

token = custom_token
print(tokenvalue)

item_object = gis.content.get(feature_layer_id)
print(item_object)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the return&lt;/P&gt;&lt;P&gt;NOTE:&amp;nbsp; The Portal and Referer are the same below.&amp;nbsp; They are both returning the same URL for my Portal instance&lt;/P&gt;&lt;LI-CODE lang="c"&gt;custom token hyLT0vo4pfs2oA3dJjPRJwRvgX-91bWD6TvS1ZZ8mOgu8aykXrL8GdoRe85kpIOvAm0BxtfXP-8IVTnjwdRelX697mjRZwhW.....UGSR3bL6jZMecwiSJT19wK4EAyw..
Token successfully generated! Expires at timestamp: 1780515639263
Portal:  https://ggg.g.ggg.gov/portal
Referer:  https://ggg.g.ggg.gov/portal
GIS Referrer:  None
None
None
&amp;lt;Item title:"DEV" type:Feature Layer Collection owner:xyz.xy@xy.xyzx.gov&amp;gt;
starting&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 13:46:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705923#M75282</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-03T13:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705926#M75283</link>
      <description>&lt;P&gt;If I run it with this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;gis = GIS(url=portal_url, token=custom_token)&lt;/LI-CODE&gt;&lt;P&gt;Instead of this&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;gis = GIS(url=portal_url, credentials={"token": custom_token})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get this error&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;....snip&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ing\script2.py", line 70, in &amp;lt;module&amp;gt;&lt;BR /&gt;gis = GIS(url=portal_url, token=custom_token)&lt;/P&gt;&lt;P&gt;....snip&lt;/P&gt;&lt;P&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 648, in _handle_json_error&lt;BR /&gt;raise Exception(errormessage)&lt;BR /&gt;Exception: Invalid token.&lt;BR /&gt;(Error Code: 498)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 13:53:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705926#M75283</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-03T13:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705935#M75284</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That looks pretty good! The timestamp doesn't expire soon and the URLs look fine, it's just the tokens are still missing for some reason.&lt;/P&gt;&lt;P&gt;Try to assemble the GIS object like this here:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gis = GIS(
    url=portal_url,
    token=custom_token,
    referer=portal_url,
    use_gen_token=True,
    verify_cert=True # I'd try this with false as well
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Personally, I've not used the credentials argument you're using, I've only done the method I've sent above, along with manually passing username and password in.&lt;/P&gt;&lt;P&gt;Also on line 30 you're reprinting the tokenvalue variable, instead of token.&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 14:31:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705935#M75284</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2026-06-03T14:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705953#M75285</link>
      <description>&lt;P&gt;OK looks like that is working but another weird thing is going on... In my payload I am setting the expiration to 1440 minutes... BUT when I get the return the token expiration date is NOT 1 day out...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;token_url = f"{portal_url}/sharing/rest/generateToken"
payload = {
    "username": portal_username,
    "password": portal_password,
    "client": "referer",
    "referer": portal_url,
    "expiration": 1440,
    "f": "json"
}

print(f"Token successfully generated! Expires at timestamp: {token_data['expires']}")

response = requests.post(token_url, data=payload)

# Example Esri epoch timestamp
esri_timestamp = token_data['expires'] 

# Convert to a readable date object
date_obj = datetime.fromtimestamp(esri_timestamp / 1000)
print(date_obj.strftime('%Y-%m-%d %H:%M:%S'))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get&amp;nbsp;&lt;/P&gt;&lt;P&gt;Token successfully generated! Expires at timestamp: 1780585244830&lt;BR /&gt;----------------------------&lt;BR /&gt;2026-06-04 11:00:44&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 15:04:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705953#M75285</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2026-06-03T15:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create token and access feature Layer</title>
      <link>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705958#M75286</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using your timestamp, it's showing me that it's one day out from my current timezone, so around 10AM CT. I may be misunderstanding what you're saying though.&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 15:07:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-token-and-access-feature-layer/m-p/1705958#M75286</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2026-06-03T15:07:37Z</dc:date>
    </item>
  </channel>
</rss>

