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/DownloadAndPublish.py", line 35, in <module>
feature_layer_item = item.publish()
File "C:\Users\aitor.calero\PycharmProjects\GISBox\venv\lib\site-packages\arcgis\gis\__init__.py", 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?
CODE:
from arcgis.gis import GIS
import urllib.request
url = r"https://datos.madrid.es/egob/catalogo/208223-7605484-trafico-intensidad-tramas.kml"
urllib.request.urlretrieve(url,"C:\\Users\\aitor.calero\\Downloads\\trafico-intensidad.kml")
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',
'type':'KML',
'file_type':'kml'}
# 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 = f.read().split('\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 [' + gis.properties.name + '] organization\n')
return gis
gis = connect_to_arcgis("https://www.arcgis.com", usr, p)
# search_item = gis.content.search('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')