<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to publish item using Item ID in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1048022#M5930</link>
    <description>&lt;P&gt;Hi Jared,&lt;/P&gt;&lt;P&gt;It's strange because from ArcGIS Pro 2.7.2 on my environment there is no problem.&lt;/P&gt;&lt;P&gt;See result below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VaccineCurrent.JPG" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/11080iA030C07847AD5AE1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VaccineCurrent.JPG" alt="VaccineCurrent.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Apr 2021 09:13:10 GMT</pubDate>
    <dc:creator>FrédéricPRALLY</dc:creator>
    <dc:date>2021-04-16T09:13:10Z</dc:date>
    <item>
      <title>Unable to publish item using Item ID</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1045081#M5906</link>
      <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;My CSV is attached. Here's my script followed by the error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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')&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;4b872c25baf7448f845e7c15912f4c9a ##&amp;lt;---this is the ouput of print statement
Traceback (most recent call last):
  File "\\Python Scripts\ArcGISPro\test.py", line 47, in &amp;lt;module&amp;gt;
    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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EDIT: &lt;/STRONG&gt;when I run the analyze() call on the CSV I get JSONDecodeError.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;analyze_csv = cm.analyze(item=item, file_type='csv')&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "\\ArcGISPro\test.py", line 41, in &amp;lt;module&amp;gt;
    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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 15:39:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1045081#M5906</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-04-08T15:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to publish item using Item ID</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1045901#M5914</link>
      <description>&lt;P&gt;Hi Jared,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First check if "Allow data to be copied to the site when publishing services" is actived under server/manager/site.html &amp;gt; data stores &amp;gt; settings.&lt;/P&gt;&lt;P&gt;Second use following modified python code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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_params = {
  'type': 'csv',
  'latitudeFieldName': 'Latitude',
  'longitudeFieldName': 'Longitude',
  'locationType': 'coordinates'
  }

#Publish
pitem = item.publish(publish_parameters=publish_params)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this can you,&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Fred&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 13:53:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1045901#M5914</guid>
      <dc:creator>FrédéricPRALLY</dc:creator>
      <dc:date>2021-04-12T13:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to publish item using Item ID</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1046752#M5917</link>
      <description>&lt;P&gt;Hi Jared,&lt;/P&gt;&lt;P&gt;Can you say me if modified python script solve this problem?&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Fred&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 06:47:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1046752#M5917</guid>
      <dc:creator>FrédéricPRALLY</dc:creator>
      <dc:date>2021-04-14T06:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to publish item using Item ID</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1046988#M5918</link>
      <description>&lt;P&gt;Hi Fred,&lt;/P&gt;&lt;P&gt;Apologies for not answering sooner. I received an error that I've yet to see once I included your snippets. I should note I'm running this in a Conda environment.&amp;nbsp; If I run it in a ArcGIS Pro environment I get the same error.&lt;/P&gt;&lt;P&gt;Here's what I ran:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
from arcgis import GIS, features
from datetime import datetime as dt
import requests

now = dt.now()
dStr = now.strftime('_%m_%d_%Y')

#Connection to ArcGIS Enterprise Portal running 10.8
gisE = GIS(url='', username='', password='', verify_cert=False, trust_env=False)
#Url to data
j = r'https://idph.illinois.gov/DPHPublicInformation/api/covidVaccine/getVaccineAdministrationCurrent'
#this print statement makes sure it's valid json
print(requests.get(j).json()['VaccineAdministration'])

r = requests.get(j).json()['VaccineAdministration']
csvData = fr'C:/Users/jpilbeam/Test/Test{dStr}.csv'

#Create DataFrame from the json
df = pd.json_normalize(r)
csv_file = df.to_csv(csvData, index=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_params = {
  'type': 'csv',
  'latitudeFieldName': 'Latitude',
  'longitudeFieldName': 'Longitude',
  'locationType': 'coordinates'
  }

#Publish
pitem = item.publish(publish_parameters=publish_params)&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;##I removed the print statement verifying the JSON is valid because it's too lengthy...
8d7744baf55f4c4287486dd830e42280 ##&amp;lt;--print output of item_id
Traceback (most recent call last):
  File "\\pathtopythonfile\test.py", line 48, in &amp;lt;module&amp;gt;
    pitem = item.publish(publish_parameters=publish_params)
  File "C:\Users\jpilbeam\Miniconda3\envs\env1\lib\site-packages\arcgis\gis\__init__.py", line 10332, in publish
    res = self._portal.con.post(path, postdata)
  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: Analyze Service error: Server tool execution failed : ERROR 001506: Failed to download the data for the portal item. Failed to execute (Analyze Features for Portal). Failed. Failed to execute (Analyze Features for Portal). Failed.
(Error Code: 0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt; The box is checked that allows data to be copied to the Portal when publishing.&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image (1).png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/10869i13504D6FFC2A9BF4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image (1).png" alt="image (1).png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 15:35:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1046988#M5918</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-04-14T15:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to publish item using Item ID</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1048022#M5930</link>
      <description>&lt;P&gt;Hi Jared,&lt;/P&gt;&lt;P&gt;It's strange because from ArcGIS Pro 2.7.2 on my environment there is no problem.&lt;/P&gt;&lt;P&gt;See result below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VaccineCurrent.JPG" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/11080iA030C07847AD5AE1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VaccineCurrent.JPG" alt="VaccineCurrent.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 09:13:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1048022#M5930</guid>
      <dc:creator>FrédéricPRALLY</dc:creator>
      <dc:date>2021-04-16T09:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to publish item using Item ID</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1048197#M5934</link>
      <description>&lt;P&gt;Yes, that seems to be a pattern. I have different versions of the script above and they all seem to work on someone outside of our office's machine/environment. One of these scripts I gave to my colleague to try on his machine--we both have accounts on the same Portal and we both are using the same Pro Python API environment--he gets the same errors as me.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 16:17:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1048197#M5934</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-04-16T16:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to publish item using Item ID</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1049646#M5956</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3171"&gt;@FrédéricPRALLY&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how to troubleshoot that error? The only help I've found on it was &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/tool-errors-and-warnings/001001-010000/tool-errors-and-warnings-01501-01525-001506.htm" target="_self"&gt;this&lt;/A&gt;. Based off this doc, I made sure the folder (which is local) where the *.csv was saved was shared to our organization's admin user account. That didn't solve the error.&lt;/P&gt;&lt;P&gt;Also, when referencing the &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html?highlight=publish#arcgis.gis.Item.publish" target="_self"&gt;publish method&lt;/A&gt; in the docs it gives you a link for publish parameters: &lt;A href="https://developers.arcgis.com/rest/#/Publish_Item/02r300000080000000/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/rest/#/Publish_Item/02r300000080000000/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But, this just brings you to the landing page of the ArcGIS REST API. Is this a mistake?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 16:21:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-publish-item-using-item-id/m-p/1049646#M5956</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-04-21T16:21:25Z</dc:date>
    </item>
  </channel>
</rss>

