I am trying to query a feature layer as described here: arcgis.features module — arcgis 1.4.2 documentation but I get KeyError: 'count' (see full error below). I'm using all the default parameters for the query, which includes return_count_only = False. I've tried this on multiple layers, including ones hosted in AGOL and ones available through our REST endpoint. Any ideas?
My code:
import arcgis.features as features
test = features.FeatureLayer("https://gis.johnsoncitytn.org/arcgis/rest/services/ReferenceData/Park_And_Recreation_Locations/MapSe...")
print(test.query())
The error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-5-b9976302e36a> in <module>()
1 import arcgis.features as features
2 test = features.FeatureLayer("https://gis.johnsoncitytn.org/arcgis/rest/services/ReferenceData/Park_And_Recreation_Locations/MapSe...")
----> 3 print(test.query())
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\layer.py in query(self, where, out_fields, time_filter, geometry_filter, return_geometry, return_count_only, return_ids_only, return_distinct_values, return_extent_only, group_by_fields_for_statistics, statistic_filter, result_offset, result_record_count, object_ids, distance, units, max_allowable_offset, out_sr, geometry_precision, gdb_version, order_by_fields, out_statistics, return_z, return_m, multipatch_option, quanitization_parameters, return_centroid, return_all_records, **kwargs)
391
392 params['returnCountOnly'] = True
--> 393 record_count = self._query(url, params)
394 if 'maxRecordCount' in self.properties:
395 max_records = self.properties['maxRecordCount']
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\layer.py in _query(self, url, params)
824
825 if params['returnCountOnly']:
--> 826 return result['count']
827 elif params['returnIdsOnly']:
828 return result
KeyError: 'count'
Solved! Go to Solution.
Hi Ellen,
It looks like you are specifying the Map/Feature Service instead of the Map/Feature Service Layer. Try adding the layer id to the end of the url you are querying:
import arcgis
layer = arcgis.features.FeatureLayer("https://gis.johnsoncitytn.org/arcgis/rest/services/ReferenceData/Park_And_Recreation_Locations/MapSe...")
layer.query()
Hi Ellen,
It looks like you are specifying the Map/Feature Service instead of the Map/Feature Service Layer. Try adding the layer id to the end of the url you are querying:
import arcgis
layer = arcgis.features.FeatureLayer("https://gis.johnsoncitytn.org/arcgis/rest/services/ReferenceData/Park_And_Recreation_Locations/MapSe...")
layer.query()
That was the problem! Thank you!