Select to view content in your preferred language

Publish CSV to Enterprise Portal Errors

6656
14
Jump to solution
03-10-2021 09:32 AM
JaredPilbeam2
MVP Alum

I'm trying to do something simple using the following help doc, but I can not seem to publish.
https://geosaurus.maps.arcgis.com/home/item.html?id=a1db6db172bc49a8932daacc2ed3d3ac#preview

I'm able to add it to the Portal, but I cannot get it to publish.

from IPython.display import display
from arcgis.gis import GIS
import os
gis = GIS('Home')

csv_file = r'C:\Users\jpilbeam\Downloads\c19_Vaccine_Current.csv'
csv_item = gis.content.add({}, csv_file)#add csv to Portal

csv_layer = csv_item.publish(None, file_type='csv')

 

Error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
In  [15]:
Line 1:     csv_layer = csv_item.publish(None, file_type='csv')

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py, in publish:
Line 10353: elif not buildInitialCache and ret[0]['type'].lower() == 'image service':

KeyError: 'type'
---------------------------------------------------------------------------

 

Other attempts:

csv_layer = csv_item.publish()

Error:
KeyError: 'type'

 

csv_layer = csv_item.publish('csv')

Error:
ValueError: dictionary update sequence element #0 has length 1; 2 is required

 

 

0 Kudos
14 Replies
MehdiPira1
Esri Contributor

@JaredPilbeam2 ,

Found the problem. The catch here is specifying none for the location type since there is no coordinates in the csv file and I didn't know publishing a csv in Portal would require some parameters (type and location type) to specify in this case, compared to publishing to AGOL which you can (also) publish without parameters.

 

params={"type":"csv","locationType":"none"}
csv_item.publish(publish_parameters=params)

 

 Make sure you first delete the defective published csv feature layer.

Cheers

Mehdi

 

0 Kudos
JaredPilbeam2
MVP Alum

@MehdiPira1 

Thanks, I was able to publish a blank CSV with those parameters! But, I'm still getting a KeyError with the CSV I actually need published. I've continued the conversation in my other post where I attached the troublesome CSV. Thanks for your help.

0 Kudos
MarcusAndersson
Regular Contributor

Hi,

I found this post quite randomly, but just wanted to let you know that the name of the Portal, your Username, and your Password is written in plain text in your post. I would suggest to edit and remove this asap.

BR,
Marcus

MehdiPira1
Esri Contributor

@JaredPilbeam2 

Not a problem.

0 Kudos
John_Herrera
Occasional Contributor

I've been using this code to upload and publish a csv file with no location to ArcGIS Enterprise (Portal).  Works fine, however recently content.add has been deprecated and running the code will throw a warning message.  Users are advised to use Folder.add.

I'm unable to locate a sample code or find anything useful researching the ArcGIS API for Python documentation.  All examples I've seen so far are for publishing csv with XY locations.  Any help you can provide getting me out of this rabbit-hole is greatly appreciated!  My code is below

from arcgis.gis import GIS
gis = GIS("home")
csv_file = r"C:\data\Demo_noLocation.csv"
csv_item = gis.content.add({}, csv_file)
display(csv_item)
params={"type":"csv","locationType":"none"}
csv_item.publish(publish_parameters=params)

0 Kudos