0

I'm following this help doc. https://geosaurus.maps.arcgis.com/home/item.html?id=a1db6db172bc49a8932daacc2ed3d3ac#preview

I'm able to add the CSV to the Portal, but I cannot get it to publish. I need it published as a table. It doesn't have coordinate fields and it's not intended to be a spatial feature.

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()
KeyError: 'type'
csv_layer = csv_item.publish('csv')
ValueError: dictionary update sequence element #0 has length 1; 2 is required
csv_layer = csv_item.publish(publishParameters={"type":"csv"})
TypeError: publish() got an unexpected keyword argument 'publishParameters'

I also tried what the help doc does. It has a text field with place name values specified in the address_fields parameter. My CountyName field is also a text field with place names. But, this also errors.

csv_flayer = csv_item.publish(None, {"Address":"CountyName"})
KeyError: 'type'

1 Answer 1

1

I found out it has something to do with the encoding of the CSV file. I was able to publish the CSV after completing the following steps.

  1. Open the CSV in a text editor (I used Notepad).

  2. Save it. Use a .csv file extension type --> Save as type: All Files --> Encoding: utf-8 enter image description here

  3. try publishing to Enterprise Portal with this:

from IPython.display import display
from arcgis.gis import GIS
import os
gis = GIS('Home') #uses current Notebook as workspace

csv_file = r'C:\pathto\your.csv' #path to CSV
csv_item = gis.content.add({}, csv_file) #add CSV to Enterprise Portal
display(csv_item) #display it here 

#location parameter needs to be set to "none" when publishing to Enterprise Portal
params={"type":"csv","locationType":"none"} 
csv_item.publish(publish_parameters=params) #publish to Enterprise Portal

This is not the fastest workflow. If you're able to set the encoding to utf-8 back when you originally create your CSV then that would be better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.