Publish CSV to Enterprise Portal Errors

2082
13
Jump to solution
03-10-2021 09:32 AM
JaredPilbeam2
MVP Regular Contributor

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
1 Solution

Accepted Solutions
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

 

View solution in original post

0 Kudos
13 Replies
JakeSkinner
Esri Esteemed Contributor

@JaredPilbeam2  try using the publishParameters parameter in the publish call.  You'll need this info if you're trying to publish the CSV as a feature service.  Ex:

 

csv_layer = csv_item.publish(publishParameters={"type":"csv","name":"XY_Locations","locationType":"coordinates","latitudeFieldName":"Latitude","longitudeFieldName":"Longtidue"})

 

The above is publishing a CSV to a feature service called XY_Locations.  It's creating the spatial content using coordinates from fields Latitude and Longitude.

 

0 Kudos
JaredPilbeam2
MVP Regular Contributor

Hi Jake,

This resulted in an error:

 

csv_layer = csv_item.publish(publishParameters={"type":"csv"})
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
In  [20]:
Line 1:     csv_layer = csv_item.publish(publishParameters={"type":"csv"})

TypeError: publish() got an unexpected keyword argument 'publishParameters'
---------------------------------------------------------------------------

 

 

I need the csv file published as a table. It doesn't have coordinate fields and it's not intended to be a spatial feature.

0 Kudos
JaredPilbeam2
MVP Regular Contributor

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                                  Traceback (most recent call last)
In  [23]:
Line 1:     csv_flayer = csv_item.publish(None, {"Address":"CountyName"})

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'
---------------------------------------------------------------------------

 

 

 

 

0 Kudos
MehdiPira1
Esri Contributor

@JaredPilbeam2 ,

I just tried to add and publish a CSV (no coordinates and no address ) to AGOL and it worked fine.

I just used the publish method without any input parameters.

 

csv_layer = csv_item.publish()

 

 I'd recommend trying to add and publish a different CSV file to check if this works for you too.

The other thing to consider is to check the field names and remove if they have any characters such as //\,()[],....

0 Kudos
JaredPilbeam2
MVP Regular Contributor

@MehdiPira1 

I already tried that, as seen above. No luck. Also, I'm working with Enterprise Portal. I don't have the option to publish to AGOL.

I tried with a blank CSV. It's throwing a KeyError still?

 

csv_file = r'C:\Users\jpilbeam\test.csv'
csv_item = gis.content.add({}, csv_file) ##It adds the CSV with no errors

csv_lyr = csv_item.publish() ## throws KeyError: 'type'

 

 

 

0 Kudos
JaredPilbeam2
MVP Regular Contributor

@MehdiPira1 

@JakeSkinner 

I'm used to my Visual Studio 2019 IDE so I brought the code over from the Pro Notebook it was in. And the error was still the same: KeyError: 'type'. Then I was checking the encoding by reading it to file. New error.

Now it's telling me to specify the type.

 

 

gis = GIS('url', 'user', 'password')

csv_file = r'C:\Users\jpilbeam\Downloads\c19_Vaccine_Current.csv'
with open(csv_file, "r") as f:
    print(f)
    csv_item = gis.content.add({}, str(f)) ##<--error is pointing here
    csv_lyr = csv_item.publish()
    print(csv_lyr)

 

 

 

 

 

<_io.TextIOWrapper name='C:\\Users\\jpilbeam\\Downloads\\c19_Vaccine_Current.csv' mode='r' encoding='cp1252'> ##<--1st print statement

Traceback (most recent call last):
  File "\\gisfile\GISstaff\Jared\Python Scripts\ArcGISPro\CSVtoPortal.py", line 11, in <module>
    csv_item = gis.content.add({}, str(f))
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 4202, in add
    raise RuntimeError('Specify type in item_properties')
RuntimeError: Specify type in item_properties

 

 

 

 

 

0 Kudos
MehdiPira1
Esri Contributor

@JaredPilbeam2 

What version of ArcGIS API for Python are you using?

Perhaps a version upgrade helps!

0 Kudos
JaredPilbeam2
MVP Regular Contributor

@MehdiPira1 
I'm using version 1.8.3. If there's been an update I'll look for it, thanks.

0 Kudos
JaredPilbeam2
MVP Regular Contributor

@MehdiPira1 

Ok, I upgraded to 1.8.4. And I tried all the same things again. Same errors.

Tried this:

csv_layer = csv_item.publish(publishParameters={"type":"csv"})

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
In  [9]:
Line 1:     csv_layer = csv_item.publish(publishParameters={"type":"csv"})

TypeError: publish() got an unexpected keyword argument 'publishParameters'
---------------------------------------------------------------------------

 

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

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
In  [11]:
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'
---------------------------------------------------------------------------

 

csv_layer = csv_item.publish()

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
In  [14]:
Line 1:     csv_layer = csv_item.publish()

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'
---------------------------------------------------------------------------

 

0 Kudos