<?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 &amp;quot;Import zip error: please refresh page and try again&amp;quot;. [Python] [rest] in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/quot-import-zip-error-please-refresh-page-and-try/m-p/1129622#M6951</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Hello everyone !&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I'm trying to migrate a french's WebAppBuilder (arcOpoleBuilder) from our dev's portal to our prod's portal. I'm succesfully zip the app but, when I'm sending the zip archive with requests, I'm encountered an issue : "Import zip error: please refresh page and try again."&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;However, when I'm sending the archive with arcopole Builder, this one works.&lt;/P&gt;&lt;P&gt;I've download winmerge to compare the zip that i've created in python and the zip who is uploaded with the archive(who is, finally, the same) and this is not totally the same :&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://i.stack.imgur.com/87FV0.png" target="_blank" rel="nofollow noopener noreferrer"&gt;Winmerge&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here is my jupyter notebook code :&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from getpass import getpass
import requests
import json
import os
from zipfile import *
import urllib
import tempfile
import shutil
import urllib.parse
import os

origine = GIS('https://xxxxxxx.fr/portal', 'xxxxxxx', "xxxxxxx", verify_cert=False)
destination = GIS('https://xxxxxxx.fr/portal', 'xxxxxxx', "xxxxxxx", verify_cert=False)
url = r"{}/webappbuilder/rest/apps/list?portalUrl={}".format(origine.url.replace("/portal", ""), origine.url)
params = {'portalUrl': origine.url, \
                  'token': origine._con.token, \
                  'f': 'json'}
reponseBrut = requests.get(url, data = params, verify = False)
reponse = json.loads(reponseBrut.text)
for appli in reponse:
    nom_appli = "TEST-WAB"
    if (appli['name'] == nom_appli):
        app = appli
        print (app['name'])
        print (app['id'])
url = r"{}/webappbuilder/rest/apps/{}/download".format(origine.url.replace("/portal", ""), 

app['id'])
params = {'token': origine._con.token, \
          'f': 'files'}
reponse = requests.get(url, data = params, verify = False)
f = open(app['name']+".zip", "wb")
f.write(reponse.content)
f.close()
with tempfile.TemporaryDirectory() as repertoireTemporaire:
print (app['id'])
cheminFichier = repertoireTemporaire + "//" + app['name'] + ".zip"
cheminFichier_TMP = repertoireTemporaire + "//tmp.zip"
#print (cheminFichier)
with ZipFile (app['name']+".zip", 'r') as zipOrigine:
    with zipOrigine.open('config.json') as fichierConfig:
        jsonConfig = json.load(fichierConfig)           
        if("portalUrl" in jsonConfig):
            jsonConfig["portalUrl"] = destination.url
            print (jsonConfig["portalUrl"])
                       
            if("map" in jsonConfig):
                map = jsonConfig["map"]
                if("portalUrl" in map):
                    jsonConfig["map"]["portalUrl"] = destination.url + "/"

                    if("itemId" in map):
                        print (jsonConfig["map"]["itemId"])
                        jsonConfig["map"]["itemId"] = "bf550f0249ae4a44baf40792b5c6da9b"
                        print (jsonConfig["map"]["itemId"])
                            
                    if("geometryService" in jsonConfig):
                        jsonConfig["geometryService"] = destination.properties['helperServices']['geometry']['url']
                        print (jsonConfig["geometryService"])
                    with ZipFile(cheminFichier_TMP, 'w') as zipDestination:
                        for fichier in zipOrigine.infolist():
                            data = None
                            if (fichier.filename not in 'config.json'):
                                data = zipOrigine.read(fichier.filename)
                            else:
                                data = json.dumps(jsonConfig, indent=4)
                                #print (data)
                            zipDestination.writestr(fichier, data)

    shutil.move(cheminFichier_TMP, cheminFichier)
    url = r"{}/webappbuilder/rest/apps/upload".format(destination.url.replace("/portal", ""))
    params = {'token': destination._con.token, \
              'f': 'json', \
              'creator': destination.properties["user"]["username"], \
              'portalUrl': 'https://xxxxx.fr'}
    fichier = open(cheminFichier, "rb")
    reponse = requests.post(url, data = params, files = {'file': fichier}, verify = False)
    fichier.close()
    print(reponse.text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;and the output :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Import zip error: please refresh page and try again.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be appreciated.&lt;/P&gt;&lt;P&gt;Have a good holiday everyone.&lt;/P&gt;&lt;P&gt;Cheers !&lt;/P&gt;&lt;P&gt;Kant1.dro&lt;/P&gt;</description>
    <pubDate>Thu, 30 Dec 2021 10:58:43 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-30T10:58:43Z</dc:date>
    <item>
      <title>"Import zip error: please refresh page and try again". [Python] [rest]</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/quot-import-zip-error-please-refresh-page-and-try/m-p/1129622#M6951</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Hello everyone !&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I'm trying to migrate a french's WebAppBuilder (arcOpoleBuilder) from our dev's portal to our prod's portal. I'm succesfully zip the app but, when I'm sending the zip archive with requests, I'm encountered an issue : "Import zip error: please refresh page and try again."&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;However, when I'm sending the archive with arcopole Builder, this one works.&lt;/P&gt;&lt;P&gt;I've download winmerge to compare the zip that i've created in python and the zip who is uploaded with the archive(who is, finally, the same) and this is not totally the same :&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://i.stack.imgur.com/87FV0.png" target="_blank" rel="nofollow noopener noreferrer"&gt;Winmerge&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here is my jupyter notebook code :&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from getpass import getpass
import requests
import json
import os
from zipfile import *
import urllib
import tempfile
import shutil
import urllib.parse
import os

origine = GIS('https://xxxxxxx.fr/portal', 'xxxxxxx', "xxxxxxx", verify_cert=False)
destination = GIS('https://xxxxxxx.fr/portal', 'xxxxxxx', "xxxxxxx", verify_cert=False)
url = r"{}/webappbuilder/rest/apps/list?portalUrl={}".format(origine.url.replace("/portal", ""), origine.url)
params = {'portalUrl': origine.url, \
                  'token': origine._con.token, \
                  'f': 'json'}
reponseBrut = requests.get(url, data = params, verify = False)
reponse = json.loads(reponseBrut.text)
for appli in reponse:
    nom_appli = "TEST-WAB"
    if (appli['name'] == nom_appli):
        app = appli
        print (app['name'])
        print (app['id'])
url = r"{}/webappbuilder/rest/apps/{}/download".format(origine.url.replace("/portal", ""), 

app['id'])
params = {'token': origine._con.token, \
          'f': 'files'}
reponse = requests.get(url, data = params, verify = False)
f = open(app['name']+".zip", "wb")
f.write(reponse.content)
f.close()
with tempfile.TemporaryDirectory() as repertoireTemporaire:
print (app['id'])
cheminFichier = repertoireTemporaire + "//" + app['name'] + ".zip"
cheminFichier_TMP = repertoireTemporaire + "//tmp.zip"
#print (cheminFichier)
with ZipFile (app['name']+".zip", 'r') as zipOrigine:
    with zipOrigine.open('config.json') as fichierConfig:
        jsonConfig = json.load(fichierConfig)           
        if("portalUrl" in jsonConfig):
            jsonConfig["portalUrl"] = destination.url
            print (jsonConfig["portalUrl"])
                       
            if("map" in jsonConfig):
                map = jsonConfig["map"]
                if("portalUrl" in map):
                    jsonConfig["map"]["portalUrl"] = destination.url + "/"

                    if("itemId" in map):
                        print (jsonConfig["map"]["itemId"])
                        jsonConfig["map"]["itemId"] = "bf550f0249ae4a44baf40792b5c6da9b"
                        print (jsonConfig["map"]["itemId"])
                            
                    if("geometryService" in jsonConfig):
                        jsonConfig["geometryService"] = destination.properties['helperServices']['geometry']['url']
                        print (jsonConfig["geometryService"])
                    with ZipFile(cheminFichier_TMP, 'w') as zipDestination:
                        for fichier in zipOrigine.infolist():
                            data = None
                            if (fichier.filename not in 'config.json'):
                                data = zipOrigine.read(fichier.filename)
                            else:
                                data = json.dumps(jsonConfig, indent=4)
                                #print (data)
                            zipDestination.writestr(fichier, data)

    shutil.move(cheminFichier_TMP, cheminFichier)
    url = r"{}/webappbuilder/rest/apps/upload".format(destination.url.replace("/portal", ""))
    params = {'token': destination._con.token, \
              'f': 'json', \
              'creator': destination.properties["user"]["username"], \
              'portalUrl': 'https://xxxxx.fr'}
    fichier = open(cheminFichier, "rb")
    reponse = requests.post(url, data = params, files = {'file': fichier}, verify = False)
    fichier.close()
    print(reponse.text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;and the output :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Import zip error: please refresh page and try again.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be appreciated.&lt;/P&gt;&lt;P&gt;Have a good holiday everyone.&lt;/P&gt;&lt;P&gt;Cheers !&lt;/P&gt;&lt;P&gt;Kant1.dro&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 10:58:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/quot-import-zip-error-please-refresh-page-and-try/m-p/1129622#M6951</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-30T10:58:43Z</dc:date>
    </item>
  </channel>
</rss>

