file_type error when creating a KML item

11-24-2018 05:06 AM
Esri Contributor

Hello, I'm trying to download a KML file and uploaded it to my ArcGIS Online account (code below). Although the scripts works well when running it shows the following error:

Traceback (most recent call last):
  File "C:/Users/aitor.calero/PycharmProjects/GISBox/Examples/", line 35, in <module>
    feature_layer_item = item.publish()
  File "C:\Users\aitor.calero\PycharmProjects\GISBox\venv\lib\site-packages\arcgis\gis\", line 5830, in publish
    raise ValueError("A file_type must be provide, data format not recognized")
ValueError: A file_type must be provide, data format not recognized

As you can see in my code I use 'file_type:kml' and I've tried also with '.kml' to no avail. Surpringsingly, the layer is published and worked. Any ideas of what I am doing wrong here?


from arcgis.gis import GIS
import urllib.request

url = r""


item_path = r"C:\\Users\\aitor.calero\\Downloads\\trafico-intensidad.kml"
item_properties={'title':'Intensidad de Tráfico',
                'description':'Intensidad de tráfico de Madrid actualizada cada 5 min',
                'tags':'tráfico, madrid, intensidad',

# we open a text file where my credentials are stored
# this file must be in the same directory
with open('../credentials.txt') as f:
    usr, p, arcgisboxdir ='\n'# or similar

# we connect to my arcgis account using the previous credentials
def connect_to_arcgis(_url, _usr, _pwd):
    gis = GIS(_url, _usr, _pwd)
    print('Connected successfully to the [' + + '] organization\n')
    return gis

gis = connect_to_arcgis("", usr, p)

# search_item ='Intensidad de Tráfico')
# item_for_deletion = gis.content.get(search_item[0].id)
# item_for_deletion.delete()

item = gis.content.add(item_properties=item_properties, data=item_path)
feature_layer_item = item.publish()

print('The ['+item['title'] +'] layer has been sucessfully published')
Tags (3)
3 Replies
MVP Emeritus

arcgis.gis module — arcgis 1.5.1 documentation 

filetype … have you tried leaving it off? the dictionary information isn't required and filetype isn't listed in the current help, whereas 'type' is

0 Kudos
Esri Contributor

Yes, I forget to mention that. Removing it does not work either. It just gives me the same error.

0 Kudos
Esri Contributor

Problem solved! Since its a KML file, you do not need to "publish()" it. You just need to create the item:

item = gis.content.add(item_properties=item_properties, data=item_path)