|
POST
|
I used to be able to use Python and auto-fill fields by putting the string in quotes. For some reason it hasn't been working lately. I'm using Pro v. 2.7.2. The expression verifies and the there are no errors, but the (text) fields are not populated with the string? The field length is set at 300, more than enough.
... View more
04-08-2021
01:24 PM
|
0
|
14
|
5905
|
|
POST
|
I want to publish a CSV to Enterprise Portal. So far, I have been unsuccessful. First, I use the content manager to add the CSV to the Portal. Then I try publishing using the Item ID of that newly added item. The item gets added, as I used a print statement to verify the Item ID. The exception is telling me it already exists? Does it not have to first exist as an item in order to publish? My CSV is attached. Here's my script followed by the error. from arcgis import GIS, features
#Connection to ArcGIS Enterprise Portal running 10.8
gisE = GIS(url='', username='', password='', verify_cert=False, trust_env=False)
cm = gisE.content
#Add CSV to ArcGIS Enterprise
item = cm.add(item_properties={
'title' : 'VaccineCurrent2',
'tags' : 'test',
'type' : 'CSV'}, data=csv_file)
item_id = item.id
print(item_id)
#Publish
pitem = item.publish(item_id=item_id, file_type='csv') 4b872c25baf7448f845e7c15912f4c9a ##<---this is the ouput of print statement
Traceback (most recent call last):
File "\\Python Scripts\ArcGISPro\test.py", line 47, in <module>
pitem = item.publish(item_id=item_id, file_type='csv')
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\__init__.py", line 10340, in publish
folder, buildInitialCache, item_id=item_id)
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\_impl\_portalpy.py", line 408, in publish_item
resp = self.con.post(path, postdata, files)
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 720, in post
force_bytes=kwargs.pop('force_bytes', False))
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 514, in _handle_response
self._handle_json_error(data['error'], errorcode)
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 536, in _handle_json_error
raise Exception(errormessage)
Exception: Unable to publish item.
Item with Id '4b872c25baf7448f845e7c15912f4c9a already exists.
(Error Code: 400) EDIT: when I run the analyze() call on the CSV I get JSONDecodeError. analyze_csv = cm.analyze(item=item, file_type='csv') Traceback (most recent call last):
File "\\ArcGISPro\test.py", line 41, in <module>
analyze_csv = cm.analyze(item=item, file_type='csv')
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\__init__.py", line 4381, in analyze
return gis._con.post(path=surl, postdata=params, files=files)
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 720, in post
force_bytes=kwargs.pop('force_bytes', False))
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 504, in _handle_response
data = resp.json()
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\requests\models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
... View more
04-08-2021
08:08 AM
|
0
|
6
|
6471
|
|
POST
|
@NKneisel Sorry, I've never used Field Maps. Have you posted about it here? https://community.esri.com/t5/arcgis-field-maps-questions/bd-p/arcgis-field-maps-question
... View more
04-05-2021
06:46 AM
|
0
|
1
|
4332
|
|
POST
|
@NKneiselIs it set to Everyone(Public) on the ArcGIS Survey123 webpage under Collaborate, and is the Hosted Feature Layer set to pubic?
... View more
04-01-2021
02:01 PM
|
0
|
1
|
4346
|
|
POST
|
You are not passing in the f=json parameter needed to get a JSON response from the REST API. I got some help on my GitHub post, but I don't know enough to know exactly where the f=json parameter is supposed to go? It is in response to the JSONDecodeError on this line: data=full_file)
... View more
04-01-2021
07:08 AM
|
0
|
1
|
2755
|
|
POST
|
Hi Mark, I still don't have a surefire way. I'm using Enterprise Portal v. 10.81. I have a case going with ESRI Support and will report back whenever I find something out.
... View more
03-31-2021
06:59 AM
|
0
|
0
|
2757
|
|
POST
|
Hi LongDinh, That's great you were able to publish. If you don't mind I'd like to pick your brain a bit more. I'm using GIS module/Python API v. 1.8.4, Portal v. 10.8. Would it be possible for you to post your code so I can see what you did? I'm looking into sending a requests.post(). Yes, I'm using ArcGIS Server v. 10.8.
... View more
03-29-2021
07:57 AM
|
0
|
1
|
6825
|
|
POST
|
I'm posting my whole script in case it helps to have the whole picture. The first part (which writes requested JSON to a CSV) works fine. It only fails where I pointed out in the above post. NOTE: this is easily reproducible. import json,requests
from arcgis.gis import GIS
import os,sys
import csv
from datetime import datetime
##-------------this part writes requested JSON to a CSV-----------
#file name
csv_file = 'blankcsv'
#the directory you want the csv written to
file_path = r'C:\Users\jpilbeam\Test'
##idph url goes here
idph_data = 'https://idph.illinois.gov/DPHPublicInformation/api/covidVaccine/getVaccineAdministrationCurrent'
full_file = os.path.join(file_path, csv_file) + str(datetime.now().strftime('_%m_%d_%Y_%H%M')) + '.csv'
#get json data from idph
response = requests.get(idph_data,verify=True)
#read the json response and keep the VaccineAdministration part
data = response.json()['VaccineAdministration']
#write to file
with open(full_file, 'w', newline='', encoding='UTF-8') as csvfile:
f = csv.writer(csvfile)
#write the headers of the csv file
f.writerow(['County','AdminCount','AdminCountChange', 'RollAvg', 'AllocDoses', 'FullyVaccinated', 'FullyVaccinatedChange', 'ReportDate', 'Pop', 'PctVaccinated', 'LHDInventory', 'CommInventory','TotalInventory', 'InventoryDate'])
for elem in data:
#get the values for all the keys (i.e. CountyName, AdministeredCount, etc...)
f.writerow([elem['CountyName'], elem['AdministeredCount'], elem['AdministeredCountChange'], elem['AdministeredCountRollAvg'], elem['AllocatedDoses'], elem['PersonsFullyVaccinated'], elem['PersonsFullyVaccinatedChange'], elem['Report_Date'], elem['Population'], elem['PctVaccinatedPopulation'], elem['LHDReportedInventory'], elem['CommunityReportedInventory'], elem['TotalReportedInventory'], elem['InventoryReportDate']])
##---------This part (is supposed to) adds then publishes to Portal---------
#provide Enterprise Portal login info here
gis_dest = GIS('portalURL', 'user', 'pass', verify_cert=False, trust_env=True)
#content manager
cm = gis_dest.content
#add the CSV file
item = cm.add(item_properties={
'type' : 'CSV',
'title' : 'VaccineCurrent',
'tags' : 'test',
'typeKeywords' : "CSV"
},
data=full_file)
#analyze the CSV file to autogenerate the publish parameters
analyze_csv = cm.analyze(item=item, file_type='csv')
pp = analyze_csv['publishParameters']
#Modify the publish parameters
#for tables ensure the `locationType` is None
pp['locationType'] = 'none'
#Publish
pitem = item.publish(publish_parameters=pp, overwrite=True, file_type='csv')
print("---done---")
... View more
03-26-2021
01:41 PM
|
0
|
0
|
2805
|
|
POST
|
If it matters, here's my whole script. My only option is to publish as a CSV because in the first part I write requested JSON to a CSV. If I run this I'll get the 'Decoding JSON has failed' error (even in a try/except) and the CSV will neither be added nor published. import json,requests
from arcgis.gis import GIS
import os,sys
import csv
from datetime import datetime
#the directory you want the csv written to
file_path = r'C:\Users\jpilbeam\Test'
#file name
csv_file = 'c19_VaccineTest'
##idph url goes here
idph_data = 'https://idph.illinois.gov/DPHPublicInformation/api/covidVaccine/getVaccineAdministrationCurrent'
#1----------------this section writes the json to a csv--------------
full_file = os.path.join(file_path, csv_file) + str(datetime.now().strftime('_%m_%d_%Y_%H%M')) + '.csv'
#get json data from idph
response = requests.get(idph_data,verify=True)
#read the json response and keep the VaccineAdministration part
data = response.json()['VaccineAdministration']
#write to file
with open(full_file, 'w', newline='', encoding='UTF-8') as csvfile:
f = csv.writer(csvfile)
#write the headers of the csv file
f.writerow(['County','AdminCount','AdminCountChange', 'RollAvg', 'AllocDoses', 'FullyVaccinated', 'FullyVaccinatedChange', 'ReportDate', 'Pop', 'PctVaccinated', 'LHDInventory', 'CommInventory','TotalInventory', 'InventoryDate'])
for elem in data:
#get the values for all the keys (i.e. CountyName, AdministeredCount, etc...)
f.writerow([elem['CountyName'], elem['AdministeredCount'], elem['AdministeredCountChange'], elem['AdministeredCountRollAvg'], elem['AllocatedDoses'], elem['PersonsFullyVaccinated'], elem['PersonsFullyVaccinatedChange'], elem['Report_Date'], elem['Population'], elem['PctVaccinatedPopulation'], elem['LHDReportedInventory'], elem['CommunityReportedInventory'], elem['TotalReportedInventory'], elem['InventoryReportDate']])
print('csv successfully written')
#2------------this section takes that csv and publishes it to Enterprise Portal--------------
#provide Enterprise Portal login info here
gis_dest = GIS('portalURL', 'user', 'pass', verify_cert=False, trust_env=True)
#content manager
cm = gis_dest.content
print('publishing to Enterprise Portal...')
try:
#add the CSV file
item = cm.add(item_properties={
'type' : 'CSV',
'title' : 'C19VaccineTest',
'tags' : 'test',
'typeKeywords' : "CSV"
},
data=full_file)
#analyze the CSV file to autogenerate the publish parameters
analyze_csv = cm.analyze(item=item, file_type='csv')
pp = analyze_csv['publishParameters']
#Modify the publish parameters
#for tables ensure the `locationType` is None
pp['locationType'] = 'none'
itemid = item.id
#Publish
item.publish(publish_parameters=pp, overwrite=True, file_type='csv', item_id=itemid)
except ValueError as e: # includes json.decoder.JSONDecodeError
print(f'Decoding JSON has failed: {e}')
print("---done---")
... View more
03-26-2021
01:31 PM
|
0
|
3
|
6851
|
|
POST
|
In a Pro Notebook if I continuously run the initial code it throws that error only until about the seventh time then it finally works. How's that?
... View more
03-26-2021
11:50 AM
|
0
|
4
|
6857
|
|
POST
|
Hi LongDinh, Thanks for the explanation. Does the decode step sort of clean up the json? After using the json module to decode I attempted to convert back to a CSV (because that's the file type I ultimately need). I just tried this real quick, but got an AttributeError. with open(myJSONFileOutput) as jFile:
jsonData = json.load(jFile)
jsonData.to_csv(r'C:\Users\jpilbeam\Test\decodedCSV.csv', encoding='utf-8', index=False) AttributeError: 'dict' object has no attribute 'to_csv' EDIT: I was able to convert that json back to a csv (I think?). with open(myJSONFileOutput) as jFile:
jsonData = json.load(jFile)
df = pd.DataFrame.from_dict(jsonData)
df.to_csv(r'C:\Users\jpilbeam\Test\decodedCSV.csv', encoding='utf-8', index=False) Then I ran the initial script on this 'decodedCSV.csv'. Same error. I guess I didn't change anything.
... View more
03-26-2021
09:06 AM
|
0
|
0
|
6866
|
|
POST
|
I'm the same person who posted about this in the ArcGIS API for Python forum. I'm trying use the publish() method in a stand-alone script. The only documentation I see for it is for the API. I'm able to publish a CSV in a Pro Notebook. But, when I try this in a python IDE the script runs but produces nothing but an error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) The error is coming from this line: }, data=fp) Script: from arcgis.gis import GIS
import os
gis_dest = GIS('portalurl', 'user', 'pass')
# data
fp = r'C:\Users\jpilbeam\Test\c19_Vaccine.csv'
# content manager
cm = gis_dest.content
# 1. add
item = cm.add(item_properties={
'type' : 'CSV',
'title' : 'c19',
'tags' : 'tags',
'typeKeywords' : "CSV"
}, data=fp)
# 2. analyze
analyze_csv = cm.analyze(item=item, file_type='csv')
pp = analyze_csv['publishParameters']
# 3. Modify the publish parameters then publish
# For tables ensure the `locationType` is None
pp['locationType'] = 'none'
pitem = item.publish(publish_parameters=pp, file_type='csv')
... View more
03-25-2021
01:54 PM
|
1
|
8
|
6936
|
|
POST
|
Is it possible to use the API publish() method in a stand alone script? The following script runs from a Pro Notebook using version 1.8.4 of the API. But, if I run the same script as a stand alone I get a JSONDecodeError. I'm trying to publish a CSV to Enterprise Portal. When I put it in a try and except block it catches the error, but nothing publishes Script that I'm running in Pro: from arcgis.gis import GIS
import os
gis_dest = GIS('Home',verify_cert=False, trust_env=True)
# data
fp = r'C:\data.csv' #path to CSV
# content manager
cm = gis_dest.content
# 1. add
item = cm.add(item_properties={
'type' : 'CSV',
'title' : 'c19_Vaccine_Current_test3',
'tags' : 'tags',
'typeKeywords' : "CSV"
},
data=fp)
# 2. analyze
analyze_csv = cm.analyze(item=item, file_type='csv')
pp = analyze_csv['publishParameters']
# 3. Modify the publish parameters then publish
# For tables ensure the `locationType` is None
pp['locationType'] = 'none'
pitem = item.publish(publish_parameters=pp, file_type='csv') Line 17 it's referring to is this line: data=fp) Traceback (most recent call last):
File "pathto\test.py", line 17, in <module>
data=fp)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 4265, in add
owner_name, folder)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_portalpy.py", line 355, in add_item
resp = self.con.post(path, postdata, files)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 720, in post
force_bytes=kwargs.pop('force_bytes', False))
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 504, in _handle_response
data = resp.json()
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
... View more
03-25-2021
09:21 AM
|
1
|
5
|
2875
|
|
POST
|
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.
... View more
03-15-2021
08:07 AM
|
0
|
0
|
6715
|
|
POST
|
@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.
... View more
03-15-2021
07:19 AM
|
0
|
0
|
2858
|
| 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
|