JSONDecodeError When Accessing a Feature Layer

3704
3
Jump to solution
02-24-2020 01:20 PM
J_R_Matchett
New Contributor III

I'm trying to query a particular feature layer (https://www.visalia.city/server/rest/services/OpenData/CurrentAddresses/FeatureServer/0)

but receive a JSONDecodeError. Here's my code and result:

from arcgis.features import FeatureLayer

adds_layer = FeatureLayer('https://www.visalia.city/server/rest/services/OpenData/CurrentAddresses/FeatureServer/0')

adds = adds_layer.query()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/site-packages/arcgis/features/layer.py", line 1019, in query
    record_count = self._query(url, params, raw=as_raw)
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/site-packages/arcgis/features/layer.py", line 1960, in _query
    raise queryException
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/site-packages/arcgis/features/layer.py", line 1930, in _query
    postdata=params, token=self._token)
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/site-packages/arcgis/gis/__init__.py", line 10101, in _token
    self._hydrate()
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/site-packages/arcgis/gis/__init__.py", line 10071, in _hydrate
    self._refresh()
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/site-packages/arcgis/gis/__init__.py", line 10038, in _refresh
    raise e
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/site-packages/arcgis/gis/__init__.py", line 10033, in _refresh
    dictdata = self._con.post(self.url, params, token=self._lazy_token)
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/site-packages/arcgis/_impl/connection.py", line 1148, in post
    resp_json = json.loads(resp_data)
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/jrmatchett/opt/anaconda3/envs/arcgis17/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I can access and query the layer just fine via its webpage or when adding it to a web map. Accessing some other feature layer properties, such as properties and metadata, generates the same error. I experience the issue when using either versions 1.6.2 or 1.7.1 of the arcgis python API.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

This question/issue intrigued me, so I spent some time last night looking into it.

The security service/device is definitely responsible for the inability of the ArcGIS API for Python to query the GIS services on the site.  The site requires both full cookie and Javascript support, the latter being the challenge for the ArcGIS API for Python.  There might be a way to get special cookie and session information in a browser and then copy it over to the ArcGIS API for Python, but it would be a bit hack-y/messy even if you could get it work.

View solution in original post

0 Kudos
3 Replies
J_R_Matchett
New Contributor III

Hmmm, maybe this is the issue. I briefly received this page when attempting to visit the feature layer's web page:

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

This question/issue intrigued me, so I spent some time last night looking into it.

The security service/device is definitely responsible for the inability of the ArcGIS API for Python to query the GIS services on the site.  The site requires both full cookie and Javascript support, the latter being the challenge for the ArcGIS API for Python.  There might be a way to get special cookie and session information in a browser and then copy it over to the ArcGIS API for Python, but it would be a bit hack-y/messy even if you could get it work.

0 Kudos
ThomasMoran
New Contributor II

I'm confused as to why this support would be exposed via the python API then? Why expose a method for something that's not supported. Is this considered to be a bug?