My post here is a continuation of my other currently unresolved post pertaining to errors while trying to publish a csv to portal with the ArcGIS Python API-- version 1.8.4. I couldn't publish to ArcGIS Enterprise Portal with this, it throws a KeyError:
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()#<--throws error
KeyError: 'type'
So now I went this route:
csv_file = r'C:\Users\jpilbeam\Downloads\c19_Vaccine_Current.csv'
csv_properties={'title':'csvtoportaltest', 'description':'test', 'tags':'python, test'}
test_csv_item = gis.content.add(item_properties=csv_properties, data=csv_file)
csv_feature_layer_item = test_csv_item.publish() #<-- threw error here
Exception: Job failed
It actually published this time, but on the data page of it it says "There was an error". And the weird thing was, just after I did this the server was down with some 500 error?
Solved! Go to Solution.
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. use a .csv file extension type --> Save as type: All Files --> Encoding: utf-8
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.
Issues · Esri/arcgis-python-api (github.com)
probably the best place to post an Issue as well
Hi Jared,
I think there might be something wrong about the csv file you are trying to publish. Can you share your csv?
I would try publishing this csv with pro and see if it throws an error.
@YuliaMamonovaYes, I have been working in Pro most of the time. I've shared my CSV. MehdiPira1 provided me the solution, found here. But, this solution only worked on a blank CSV. I still get a KeyError when using the attached CSV. There aren't any special characters that I know of. Thanks for taking a look at it.
Hi @JaredPilbeam2 ,
I answered your same question in the following link:
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. use a .csv file extension type --> Save as type: All Files --> Encoding: utf-8
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.