|
POST
|
@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.
... View more
03-15-2021
07:17 AM
|
0
|
0
|
6716
|
|
POST
|
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?
... View more
03-12-2021
02:09 PM
|
1
|
6
|
6799
|
|
POST
|
@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'
---------------------------------------------------------------------------
... View more
03-12-2021
09:48 AM
|
0
|
2
|
7078
|
|
POST
|
@MehdiPira1 I'm using version 1.8.3. If there's been an update I'll look for it, thanks.
... View more
03-12-2021
08:16 AM
|
0
|
0
|
7081
|
|
POST
|
@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
... View more
03-11-2021
01:31 PM
|
0
|
6
|
7106
|
|
POST
|
@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'
... View more
03-11-2021
07:16 AM
|
0
|
7
|
7117
|
|
POST
|
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'
---------------------------------------------------------------------------
... View more
03-10-2021
01:45 PM
|
0
|
0
|
7152
|
|
POST
|
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.
... View more
03-10-2021
11:32 AM
|
0
|
1
|
7167
|
|
POST
|
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
... View more
03-10-2021
09:32 AM
|
0
|
14
|
10078
|
|
POST
|
I'm at the mercy of you experts. I tried that and it worked flawlessly at first glance. I have a bunch of fields that don't need counted, so that excluded list is great. Is this a type of f-string? fr"{fld}_cnts" I'm giving you guys all the credit for updating this little program. Thank you very much!
... View more
02-26-2021
01:28 PM
|
0
|
1
|
3157
|
|
POST
|
So I guess where I'm still stuck is getting the count back into the new fields. I left the cursor2 block at the occ variable. infeature = r"C:\pathto\backup_02232021_TESTDELETE" #name of feature class goes here
fields = ["name", "location_string_output", "email_address", "cell_phone_number",
"home_phone_number"]
for field_out in fields: #add new fields
arcpy.AddField_management(infeature, "COUNT_"+field_out,"SHORT")
values_list= []
with arcpy.da.SearchCursor(infeature, fields) as cursor1:
for row in cursor1:
#access each field value by the index i then append
for i in range(0,len(fields)):
#you access a value by a row index, this starts at 0 from the
#first field input - i.e. "name" field values are at row[0]
values_list.append(row[i])
with arcpy.da.SearchCursor(infeature, fields) as cursor2:
for row in cursor2:
for i in range(0,len(fields)):
#get the value of the field in the row
value = row[i]
#count how often it appears in values_list
occ = values_list.count(value) I'm not sure how to use the below code you provided to update the new fields with the value count? fields = ["name", "location_string_output", "email_address", "cell_phone_number",
"home_phone_number"]
#list to contain the new fields
new_fields = []
for field in fields:
field_out = "COUNT_" + field
#add the fields to all_fields
new_fields.append(field_out)
#list to contain all fields, this is used as fields list
#in the update cursor - to do this we just add the lists together!
all_fields = fields + new_fields
... View more
02-26-2021
09:31 AM
|
0
|
1
|
3176
|
|
POST
|
Sorry.. here's the whole script. I'm in the middle of digesting your latest post. infeature = r"pathto\DuplicateTesting.gdb\backup_02232021_TESTDELETE"
fields = ["name", "location_string_output", "email_address", "cell_phone_number",
"home_phone_number"]
for field_out in fields: #add new fields
arcpy.AddField_management(infeature, "COUNT_"+field_out,"SHORT")
values_list= []
with arcpy.da.SearchCursor(infeature, fields) as cursor1:
#dont append the row to the list, append the values
#this isnt perfect either, throwing everything into one list,
#ie what if someone puts a home and mobile number as the same
#it gets counted as well, so this needs to be improved later
for row in cursor1:
#access each field value by the index i then append
for i in range(0,len(fields)):
#you access a value by a row index, this starts at 0 from the
#first field input - i.e. "name" field values are at row[0]
values_list.append(row[i])
#values_list is now a giant list of every value in all those fields
with arcpy.da.UpdateCursor(infeature, fields) as cursor2:
for row in cursor2:
#the same concept - loop over your fields - the original script was
#only designed for 1 field so you need these loops (maybe!)
for i in range(0,len(fields)):
#get the value of the field in the row
value = row[i]
#count how often it appears in values_list
occ = values_list.count(value)
#you want to know the field it occurs in also!
#(i know you want to insert these values into the newly created
#fields, but it will be handy to know the field
#in the print statement for now
#get that field value by using i as an index to access fields list
#N.B. !!! this will print alot of values
#print(fields[i] + " - value - " + str(value) + " - Count - " + str(occ))
field_out.append(occ)
... View more
02-25-2021
02:19 PM
|
0
|
1
|
5475
|
|
POST
|
Been spinning my wheels. I've tried this amongst other things: with arcpy.da.UpdateCursor(infeature, fields) as cursor2:
for row in cursor2:
for i in range(0,len(fields)):
value = row[i]
occ = values_list.count(value)
for field in field_out:
cursor2.updateRow(field) But it gives me this error: File "pathto\DuplicateFields_updated.py", line 47, in <module>
cursor2.updateRow(field)
TypeError: sequence size must match size of the row
... View more
02-25-2021
01:53 PM
|
0
|
5
|
5482
|
|
POST
|
Yep, running now! The range() function was what I was missing (struggling to come up with).
... View more
02-25-2021
11:32 AM
|
0
|
7
|
5498
|
|
POST
|
David, Thanks for the very detailed response! On the first go, it through the following error. occ = list.count(i) #<-- line that threw the error
Error:
TypeError: descriptor 'count' requires a 'list' object but received a 'int'
... View more
02-25-2021
11:16 AM
|
0
|
9
|
5512
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-25-2026 12:25 PM | |
| 1 | 05-04-2026 08:45 AM | |
| 1 | 04-20-2026 01:20 PM | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM |
| Online Status |
Offline
|
| Date Last Visited |
Friday
|