Key Error when publishing shapefile into feature layer

12-10-2020 06:56 AM
New Contributor II

Greetings all,

I followed the workflow as shown on the follow page ( and am receive a key error when attempting to publish my shapefile into a feature layer.  My code used to work fine and started throwing an error after no changes were made. My code and error are found below

#Add the shapefile as an item (which publishes perfectly fine)

item_prop = {'title': '2021 NPU Applications', 'tags': 'GIS', 'type':'Shapefile'}
shapefile_item = gis.content.add(item_properties=item_prop, data=my_shapefile)

#Publish the shapefile item into a feature layer (which throws an error)
Applications_item = shapefile_item.publish()


KeyError                                  Traceback (most recent call last)
<ipython-input-24-2d2a4fbd26be> in <module>
      1 #Publish the shapefile item into a feature layer
----> 2 Applications_item = shapefile_item.publish()
      3 Applications_item

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\ in publish(self, publish_parameters, address_fields, output_type, overwrite, file_type, build_initial_cache)
   8860         elif not buildInitialCache and output_type is not None and output_type.lower() in ['sceneservice']:
   8861             return Item(self._gis, ret[0]['serviceItemId'])
-> 8862         elif not buildInitialCache and ret[0]['type'].lower() == 'image service':
   8863             return Item(self._gis, ret[0]['serviceItemId'])
   8864         else:

KeyError: 'type'   


0 Kudos
5 Replies
MVP Esteemed Contributor

Moving this to the api for python questions community

ArcGIS API for Python - GeoNet, The Esri Community

... sort of retired...
0 Kudos
New Contributor II

Thanks for that

0 Kudos
New Contributor II

Since my error was dealing with the default parameters being recognized correctly, I instead typed out the parameters which I found here (

Hence I used the code: 

#Publish the shapefile item into a feature layer
Applications_item = stapefile_item.publish(publish_parameters=None, address_fields=None, output_type=None, overwrite=False, file_type=None, build_initial_cache=False)

*I thought this was a solution but it did not

0 Kudos
Esri Contributor

Hi @SharitaU ,

I've already provided two scripts in the link below for appending and overwriting a feature layer:

I hope that helps.

0 Kudos
New Contributor II

I am experiencing the same problem. Uploading the shapefile is OK but publishing it is not. I can publish it manually on ArcGIS Online. I don't think it's a issue with file overwriting as I tried to rename it every time. Have you solved this problem?

0 Kudos