<?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: publish() to Enterprise Portal in stand alone script in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042966#M5873</link>
    <description>&lt;P&gt;Alright I will post on Github as well.&lt;/P&gt;&lt;P&gt;If you look at my script below, the json parameter is being passed as a method. This is the same as passing the parameter 'f=json'. You are accomplishing the same thing by using 'response.json()'. At least that is how I understand it.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;r = requests.get(j).json()['VaccineAdministration']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Apr 2021 16:47:13 GMT</pubDate>
    <dc:creator>MarkKinnaman</dc:creator>
    <dc:date>2021-04-01T16:47:13Z</dc:date>
    <item>
      <title>publish() to Enterprise Portal in stand alone script</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1040658#M5812</link>
      <description>&lt;P&gt;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&lt;/P&gt;&lt;P&gt;Script that I'm running in Pro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line 17 it's referring to is this line:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;data=fp)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "pathto\test.py", line 17, in &amp;lt;module&amp;gt;
    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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 16:25:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1040658#M5812</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-03-25T16:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: publish() to Enterprise Portal in stand alone script</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1041215#M5826</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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---")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 20:43:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1041215#M5826</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-03-26T20:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: publish() to Enterprise Portal in stand alone script</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042350#M5855</link>
      <description>&lt;P&gt;I saw your post on github (and the other post here) and was wondering if you got this to work. I am having the same issue when publishing to portal, but not when publishing to AGOL.&lt;/P&gt;&lt;P&gt;What enterprise/portal version are you trying to publish to? I am currently using 10.6.1.&lt;/P&gt;&lt;P&gt;I took a slightly different approach to you, but got the same result.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
import json
from arcgis import GIS

j = 'https://idph.illinois.gov/DPHPublicInformation/api/covidVaccine/getVaccineAdministrationCurrent'

r = requests.get(j).json()['VaccineAdministration']

df = pd.json_normalize(r)

#AGOL Connection
gis = GIS(url='URL', username= 'username', password='password')

#Enterprise Portal Connection
gisE = GIS(url='URL', username='username', password='password')

cm = gisE.content

item = cm.add(item_properties={
    'type' : 'CSV',
    'title' : 'VaccineCurrent',
    'tags' : 'test',
    'typeKeywords' : 'CSV'}, data='/media/WDB/Backup/Projects/data/IDataa.csv')

cm.analyze(item=item, file_type='csv', location_type='none')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 12:25:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042350#M5855</guid>
      <dc:creator>MarkKinnaman</dc:creator>
      <dc:date>2021-03-31T12:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: publish() to Enterprise Portal in stand alone script</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042368#M5856</link>
      <description>&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 13:59:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042368#M5856</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-03-31T13:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: publish() to Enterprise Portal in stand alone script</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042872#M5869</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;You are not passing in the f=json parameter needed to get a JSON response from the REST API.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got some help on my &lt;A href="https://github.com/Esri/arcgis-python-api/issues/947" target="_self"&gt;GitHub post&lt;/A&gt;, but I don't know enough to know exactly where the &lt;EM&gt;f=json&lt;/EM&gt; parameter is supposed to go? It is in response to the JSONDecodeError on this line:&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;LI-CODE lang="python"&gt;data=full_file)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 14:12:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042872#M5869</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-04-01T14:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: publish() to Enterprise Portal in stand alone script</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042966#M5873</link>
      <description>&lt;P&gt;Alright I will post on Github as well.&lt;/P&gt;&lt;P&gt;If you look at my script below, the json parameter is being passed as a method. This is the same as passing the parameter 'f=json'. You are accomplishing the same thing by using 'response.json()'. At least that is how I understand it.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;r = requests.get(j).json()['VaccineAdministration']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 16:47:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/publish-to-enterprise-portal-in-stand-alone-script/m-p/1042966#M5873</guid>
      <dc:creator>MarkKinnaman</dc:creator>
      <dc:date>2021-04-01T16:47:13Z</dc:date>
    </item>
  </channel>
</rss>

