ArcGIS Python API – How to Download ArcGIS Online Feature Service Using ArcGIS Python API

arcgis-onlinearcgis-python-apifeature-service

I rarely use ArcGIS Online but I have been tasked to download all layers on this https://services5.arcgis.com/gFh7gtZrHd449arT/arcgis/rest/services/greenez514_SW5_District_Layers/FeatureServer

I found some code I am mirroring but I keep getting an error here

import arcgis
from arcgis.gis import GIS
gis = GIS(None,'', '', verify_cert=False)
service = gis.content.get('f6325cf72860419b8f75bae4259344a5')
print(service.title)
result = service.export('  {}'.format(service.title), 'File Geodatabase', parameters=None, wait=True) 

this is the error I get

SW5 District Layers
Traceback (most recent call last):
  File "disagree.py", line 8, in <module>
    result = service.export('  {}'.format(service.title), 'File Geodatabase', parameters=None, wait='True') 
  File "/home/raphael/.local/lib/python3.8/site-packages/arcgis/gis/__init__.py", line 10855, in export
    export_item = Item(gis=self._gis, itemid=res["exportItemId"])
KeyError: 'exportItemId'

Best Answer

You're creating an anonymous connection to ArcGIS.com, then the code is attempting to generate a FileGDB. As you're anonymous, the FileGDB you're requesting has no place to go.

If you have an account in ArcGIS.com, I'd first try to login with that. However, even after that, you might not be able to export to a FileGDB; the content owner may have this ability blocked.

Related Question