Key Error when publishing shapefile into feature layer

1655
5
12-10-2020 06:56 AM
SharitaU
New Contributor II

Greetings all,

I followed the workflow as shown on the follow page (https://developers.arcgis.com/python/sample-notebooks/overwriting-feature-layers/) 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)
shapefile_item

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

 

---------------------------------------------------------------------------
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\__init__.py 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
DanPatterson
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
SharitaU
New Contributor II

Thanks for that

0 Kudos
SharitaU
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 (https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.publish)

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)
Applications_item

*I thought this was a solution but it did not

0 Kudos
MehdiPira1
Esri Contributor

Hi @SharitaU ,

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

https://community.esri.com/t5/arcgis-api-for-python-questions/correct-workflow-for-publishing-then-u...

I hope that helps.

0 Kudos
LamberWBY
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