<?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: Overwrite existing item fails in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-existing-item-fails/m-p/1295137#M8750</link>
    <description>&lt;P&gt;Ok it looks like a simple misunderstanding... I think the data= property on .update is simply the full path/filename, not the ZipFile object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;extractFolder = r'\\Scripts\Survey123\mmpkUpdate\downloaded'
zip_path = os.path.join(extractFolder,'{}.zip'.format('FS_From_Connect'))
data_item.update(item_properties=props, data=zip_path)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 01 Jun 2023 19:55:32 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2023-06-01T19:55:32Z</dc:date>
    <item>
      <title>Overwrite existing item fails</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-existing-item-fails/m-p/1295099#M8749</link>
      <description>&lt;P&gt;Attempting to convert older python 2.7 script with Python API that overwrites and existing "Form" item on our org AGO.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Context: a survey123 form item is downloaded, unzipped, media folder updated with new mmpk, re-zipped and then POST request was made to the same AGO item.&amp;nbsp; This worked just fine for py 2.7 but I've had to rewrite for the Pyhon API and running into this issue.&lt;/P&gt;&lt;P&gt;When i review the contents of the zip it appears everything is correct but the last step fails to upload/overwrite with:&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;AttributeError:&amp;nbsp;'ZipFile'&amp;nbsp;object&amp;nbsp;has&amp;nbsp;no&amp;nbsp;attribute&amp;nbsp;'decode'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def updateZip(mmpk_file):

    mediaFolder = Path('./downloaded/esriinfo/media')
    targetFile = os.path.join(mediaFolder, 'quickMMPK.mmpk')

    #copy mmpk into medial folder
    shutil.copy(mmpk_file, targetFile)

    # compress the contents of esriinfo into a new zip file
    extractFolder = Path('./downloaded')
    esriInfoFolder = Path('./downloaded/esriinfo')
    outputFileName = extractFolder.joinpath('esriinfo')

    zip_path = extractFolder.joinpath('{}.zip'.format('FS_From_Connect'))
    #zip_file = zip_path #ZipFile(zip_path)
    zf = ZipFile(zip_path, "w")

    os.chdir(extractFolder)

    for dirname, subdirs, files in os.walk('esriinfo'):
      for filename in files:
        zf.write(os.path.join(dirname, filename))

    zf.close()

    # `ContentManager.get` will return `None` if there is no Item with ID `0ccabee15e76442483d50d82ae0c4053`
    data_item = gis.content.get(surveyFormItem)

    props = {
    "type":"form",
    "title":data_item.title,
    "overwrite":True
    }

    data_item.update(item_properties=props, data=zf) #AttributeError: 'ZipFile' object has no attribute 'decode'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 18:39:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-existing-item-fails/m-p/1295099#M8749</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2023-06-01T18:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite existing item fails</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-existing-item-fails/m-p/1295137#M8750</link>
      <description>&lt;P&gt;Ok it looks like a simple misunderstanding... I think the data= property on .update is simply the full path/filename, not the ZipFile object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;extractFolder = r'\\Scripts\Survey123\mmpkUpdate\downloaded'
zip_path = os.path.join(extractFolder,'{}.zip'.format('FS_From_Connect'))
data_item.update(item_properties=props, data=zip_path)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 01 Jun 2023 19:55:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-existing-item-fails/m-p/1295137#M8750</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2023-06-01T19:55:32Z</dc:date>
    </item>
  </channel>
</rss>

