<?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: 'error': {'code': 498, 'message': 'Invalid Token' in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1258692#M8377</link>
    <description>&lt;P&gt;Hi David, I am getting a similar error in a standalone ArcGIS Server 10.5.1. I am trying to view a map services' item information (url = ServerURL/admin/services/ServiceName.MapServer/iteminfo/manifest/manifest.json).&lt;BR /&gt;I am able to generate the token but when I get the error as a response.&amp;nbsp;&lt;BR /&gt;Any ideas on how to resolve or troubleshoot? This error does not occur in ArcGIS Enterprise 10.8.1&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jxl090120_0-1676494551672.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62967i0B9526805E340353/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jxl090120_0-1676494551672.png" alt="jxl090120_0-1676494551672.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Feb 2023 20:56:30 GMT</pubDate>
    <dc:creator>Joel_Lopez</dc:creator>
    <dc:date>2023-02-15T20:56:30Z</dc:date>
    <item>
      <title>'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007319#M5271</link>
      <description>&lt;P&gt;I used the ESRI Python token code sample, which returns a token.&lt;/P&gt;&lt;P&gt;However when I use the token in &amp;lt;url+token&amp;gt;, I get an error??&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;formatted_json = [feature['attributes'] for feature in raw_json['features']]
KeyError: 'features'
{'error': {'code': 498, 'message': 'Invalid Token', 'details': []}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ef get_token():
    params = {'username': username, 'password': password, 'expiration': str(60), 'client': 'referer', 'referer': referer, 'grant_type': 'client_credentials', 'client_id': client_id, 'client_secret': client_secret,   'f': 'json'}
    request = requests.get(token_url, params=params)
    response = request.json()
    #print(response)
    token = response['access_token']
    return token

portalToken = get_token()
#### THIS works + returns Token
#print(portalToken)
##print("END")

if __name__ == "__get_token__":
    """optional location for parameters"""
    print(sys.argv[0])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The get_token returns a token.. they all seem to have .. at the end of the token?? This is really frustrating, would appreciate any pointers!!&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Clive&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 11:34:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007319#M5271</guid>
      <dc:creator>Clive_S</dc:creator>
      <dc:date>2020-12-07T11:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007320#M5272</link>
      <description>&lt;P&gt;I changed&lt;/P&gt;&lt;P&gt;&amp;nbsp;the get to post, still getting invalid token error.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;request = requests.get(token_url, params=params)

to
request = requests.post(token_url, params=params)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 11:38:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007320#M5272</guid>
      <dc:creator>Clive_S</dc:creator>
      <dc:date>2020-12-07T11:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007326#M5273</link>
      <description>&lt;P&gt;what does the query url look like with the token appended? do you have:&lt;/P&gt;&lt;P&gt;"&amp;amp;token=" + token&lt;/P&gt;&lt;P&gt;request.get(https://blablabla?f=json&amp;amp;token=hfwjfjkewkjfwkfjk..&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 12:10:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007326#M5273</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-12-07T12:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007329#M5274</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;I updated the code, got a more useful error.... I think??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;def get_token(url, username, password):
    ''' use this to get a token from arcgis online '''
    gen_token_url = token_url
    # payload params for the post request
    params = {'username':username, 'password':password,'client':'referer', 'referer':url, 'client_id': client_id, 'client_secret': client_secret, 'grant_type': grant_type, 'expiration':expiration, 'f':'json'}

    response = requests.post(gen_token_url, data=params, verify=False)
    data = response.json() # convert to json
    print('access_token')
    #return data['access_token']

mytoken = get_token(url, username, password)

if __name__ == "__get_token__":
    """optional location for parameters"""
    print(sys.argv[0])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added:&amp;nbsp;client_id, &lt;SPAN&gt;'client_secret'&lt;/SPAN&gt;: client_secret, &lt;SPAN&gt;'grant_type'&lt;/SPAN&gt;: grant_type&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I am getting&amp;nbsp; a new error:&amp;nbsp;InsecureRequestWarning: Unverified HTTPS request.&lt;/P&gt;&lt;H3&gt;redirect_uri not specified&lt;/H3&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want users to login!!&amp;nbsp; I want to get a token to login&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 12:19:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007329#M5274</guid>
      <dc:creator>Clive_S</dc:creator>
      <dc:date>2020-12-07T12:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007330#M5275</link>
      <description>&lt;P&gt;Yep, again, what is the request you're attempting?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 12:25:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007330#M5275</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-12-07T12:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007332#M5276</link>
      <description>&lt;P&gt;Hi David.&lt;/P&gt;&lt;P&gt;I need to automate getting the Token.&lt;/P&gt;&lt;P&gt;The previous code returned a Token, but threw an invalid Token error consuming the REST end point (json = URL+Token).&lt;/P&gt;&lt;P&gt;I have a rest endpoint and URL.&lt;/P&gt;&lt;P&gt;If I go to&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;'&lt;A href="https://mycomp.maps.arcgis.com/sharing/rest/oauth2/token" target="_blank"&gt;https://mycomp.maps.arcgis.com/sharing/rest/oauth2/token&lt;/A&gt;', this provides a Token&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Then if I use: json_file = url+token, this returns JSON.&lt;/P&gt;&lt;P&gt;Is this clearer??&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 12:35:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007332#M5276</guid>
      <dc:creator>Clive_S</dc:creator>
      <dc:date>2020-12-07T12:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007335#M5277</link>
      <description>&lt;P&gt;what i mean is that since the issue seems to be the format of the post or get to your rest endpoint, it would be helpful to share what it looks like.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 12:42:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007335#M5277</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-12-07T12:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007340#M5278</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;In the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#def get_token(url, username, password):
def get_token():
    ''' use this to get a token from arcgis online '''
    gen_token_url = token_url
    # payload params for the post request
    params = {'username':username, 'password':password,'client':'referer', 'referer':url, 'client_id': client_id, 'client_secret': client_secret, 'grant_type': grant_type, 'expiration':expiration, 'f':'json'}

    response = requests.post(gen_token_url, data=params, verify=False)
    data = response.json() # convert to json
    return data['access_token']

mytoken = get_token()
print(get_token) &amp;lt;&amp;lt;&amp;lt;  warning&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The warning is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;The error/warnig:
C:\Users\user\anaconda3\python.exe C:/Users/user/PycharmProjects/pythonProject1/Test.py
C:\Users\user\anaconda3\lib\site-packages\urllib3\connectionpool.py:979: InsecureRequestWarning: Unverified HTTPS request is being made to host 'eiffagekier.maps.arcgis.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  warnings.warn(

InsecureRequestWarning: Unverified HTTPS request is being made to host&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 13:10:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007340#M5278</guid>
      <dc:creator>Clive_S</dc:creator>
      <dc:date>2020-12-07T13:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007345#M5279</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;I thought that stated at the beginning of the post that if I create a Token using the Portal Form.&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="GenerateToken.PNG" style="width: 602px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1583i383A43D6CC1369D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="GenerateToken.PNG" alt="GenerateToken.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Then use that token in the REST url.&lt;/P&gt;&lt;P&gt;json_file = url+token, this returns the JSON. The issue that I have is trying to generate a Token.&lt;/P&gt;&lt;P&gt;This returns the error message/s.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 13:19:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007345#M5279</guid>
      <dc:creator>Clive_S</dc:creator>
      <dc:date>2020-12-07T13:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007357#M5280</link>
      <description>&lt;P&gt;OK.&lt;/P&gt;&lt;P&gt;Assuming username, password and url parameters are correct, your request seems to be missing headers -&amp;nbsp;headers = {'content-type': 'application/x-www-form-urlencoded'}&lt;/P&gt;&lt;P&gt;are you passing the url as&amp;nbsp;url = portalUrl + '/sharing/rest/generateToken?'&lt;/P&gt;&lt;P&gt;Also can't see the parameters of clientid secret and granttype.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests


portalUrl = "https://domain/portal"
username = 'username'
password = "password"


def generateToken(username, password, portalUrl):
    # Retrieves a token to be used with API requests.
    headers = {'content-type': 'application/x-www-form-urlencoded'}
    parameters = {'username': username,
                  'password': password,
                  'client': 'referer',
                  'referer': portalUrl,
                  'expiration': 60,
                  'f': 'json'}
    url = portalUrl + '/sharing/rest/generateToken?'
    response = requests.post(url, data=parameters, headers=headers)

    try:
        jsonResponse = response.json()
        
        if 'token' in jsonResponse:
            return jsonResponse['token']
        elif 'error' in jsonResponse:
            print (jsonResponse['error']['message'])
            for detail in jsonResponse['error']['details']:
                print (detail)
    except ValueError:
        print('An unspecified error occurred.')
        print(ValueError)


        
token = generateToken(username, password, portalUrl)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 14:24:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007357#M5280</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-12-07T14:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007367#M5281</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;Thanks that header (&lt;/P&gt;&lt;PRE&gt;headers = {&lt;SPAN&gt;'content-type'&lt;/SPAN&gt;: &lt;SPAN&gt;'application/x-www-form-urlencoded'&lt;/SPAN&gt;}) Solved the problem.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much appreciated&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 14:41:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1007367#M5281</guid>
      <dc:creator>Clive_S</dc:creator>
      <dc:date>2020-12-07T14:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1258692#M8377</link>
      <description>&lt;P&gt;Hi David, I am getting a similar error in a standalone ArcGIS Server 10.5.1. I am trying to view a map services' item information (url = ServerURL/admin/services/ServiceName.MapServer/iteminfo/manifest/manifest.json).&lt;BR /&gt;I am able to generate the token but when I get the error as a response.&amp;nbsp;&lt;BR /&gt;Any ideas on how to resolve or troubleshoot? This error does not occur in ArcGIS Enterprise 10.8.1&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jxl090120_0-1676494551672.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62967i0B9526805E340353/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jxl090120_0-1676494551672.png" alt="jxl090120_0-1676494551672.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 20:56:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1258692#M8377</guid>
      <dc:creator>Joel_Lopez</dc:creator>
      <dc:date>2023-02-15T20:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1258708#M8378</link>
      <description>&lt;P&gt;Hi, maybe best to create a new post to get more traction.&amp;nbsp; I don't really understand why you're passing a token when you have the GIS object, or why you are using a mix of the Python API and REST API, is there a sample you're working from?&lt;BR /&gt;I can dig out a python API script to extract manifest details if you like?&amp;nbsp; What do you need to achieve exactly?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 21:29:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1258708#M8378</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2023-02-15T21:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1291077#M8708</link>
      <description>&lt;P&gt;Hi jxl090120,&lt;/P&gt;&lt;P&gt;Have you resolved this error? I am having the same problem! I also want to request content of manifest json. I would appreciate with any suggestions!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lin&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 14:49:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1291077#M8708</guid>
      <dc:creator>haoechibubao</dc:creator>
      <dc:date>2023-05-19T14:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1292253#M8724</link>
      <description>&lt;P&gt;Hey David, at the time I didn't realize I could get to the manifest properties from the service object&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":expressionless_face:"&gt;😑&lt;/span&gt;&amp;nbsp;(i.e service.iteminformation.manifest). Doing so revolved my issue.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 19:02:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1292253#M8724</guid>
      <dc:creator>Joel_Lopez</dc:creator>
      <dc:date>2023-05-23T19:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: 'error': {'code': 498, 'message': 'Invalid Token'</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1292254#M8725</link>
      <description>&lt;P&gt;Hi Lin, I ended up just getting to the manifest info through the service object.&lt;BR /&gt;services = gis_server.services.list()&lt;BR /&gt;for service in services:&lt;BR /&gt;&amp;nbsp; &amp;nbsp;man = service.iteminformation.manifest&lt;BR /&gt;&amp;nbsp; &amp;nbsp;print(man)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 19:06:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-498-message-invalid-token/m-p/1292254#M8725</guid>
      <dc:creator>Joel_Lopez</dc:creator>
      <dc:date>2023-05-23T19:06:39Z</dc:date>
    </item>
  </channel>
</rss>

