question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Token Required - Error 499: When Attempting to Query Feature Layer (Arcgis 1.8.2)

See original GitHub issue

Hello - please see below:

from arcgis.gis import GIS

gis = GIS("https://portalname.domain.com/webadapter_name", 
          client_id='1234_sample_client_id', 
          verify_cert=False)

This successfully opens up a browser and I login with IWA…

print("Successfully logged in as: " + gis.properties.user.username)

This returns a success message and I am able to explore my content in the Portal

l = gis.content.get('1234567_item_sample_id')
fl = l.layers[0]

I am able to get content (that is not shared/public) and use methods such as l.get_data()

fl.query(where="1=1")

This is where the failure occurs, and I am given an Exception “Token Required (Error Code: 499”

Full failure below:

  File "<ipython-input-9-e7d33acb2760>", line 3, in <module>
    fl.query(where="1=1")

  File "C:\*****************\Anaconda3\lib\site-packages\arcgis\features\layer.py", line 1048, in query
    record_count = self._query(url, params, raw=as_raw)

  File "C:\*****************\Anaconda3\lib\site-packages\arcgis\features\layer.py", line 2048, in _query
    raise queryException

  File "C:\*****************\Anaconda3\lib\site-packages\arcgis\features\layer.py", line 2018, in _query
    postdata=params, token=self._token)

  File "C:\*****************\Anaconda3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 710, in post
    force_bytes=kwargs.pop('force_bytes', False))

  File "C:\*****************\Anaconda3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 505, in _handle_response
    self._handle_json_error(data['error'], errorcode)

  File "C:\*****************\Anaconda3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 523, in _handle_json_error
    raise Exception(errormessage)

Exception: Token Required
(Error Code: 499)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
jrmatchettcommented, Dec 9, 2020

I’ve been experiencing the same issue with arcgis version 1.8.x. Digging through the code, it appears that several FeatureLayer methods, such as query, issue a call to a Connection object’s post method, which requires a token to be specified. All those calls set the token parameter to self._token; however, _token is apparently not being set for a FeatureLayer object. The token does exist in the FeatureLayer’s Connection attribute (ie. self._con.token). I’m able to monkey patch FeatureLayer by adding a property that returns the token:

from arcgis.features import FeatureLayer
FeatureLayer._token = property(lambda self: self._con.token)

Querying then works properly.

1reaction
achapkowskicommented, Jan 8, 2021

@rodrigoalmeida94 thank you for letting us know about your issues and please continue to let us know if you encounter anything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Authentication token required. (status code 499)
The error occurs when the layers are added from a previous project, for example, the layer is opened through ArcGIS Online by selecting...
Read more >
Query (Feature Service/Layer)—ArcGIS REST APIs
The query operation returns either a feature set, an array of feature IDs, and/or a result extent.
Read more >
Authentication Error 499 using ArcGIS API for Python?
token = gis._con.token print(token). But If I try to create a FeatureLayer and search, I get an authentication error (499):
Read more >
c# - How to generate a token to query a REST ArcGIS service?
This service is a private one and requires token-based authentication to access the data within the service. Since I am new to ArcGIS,...
Read more >
Esri ArcGIS Feature Service Reader - FME Community
i'm attempting to use Esri ArcGIS Feature Service Reader and it is secured in fme 2018.1 it gives me this error (This may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found