<?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 Python Script to Auto update Web Map from Arc Pro project in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-to-auto-update-web-map-from-arc-pro/m-p/1709394#M75296</link>
    <description>&lt;P&gt;I would like to create a python Script to automatically update my web map from my ArcPro project.&lt;/P&gt;&lt;P&gt;I have a ArcPro project that I manually update the web map right now.&lt;/P&gt;&lt;P&gt;I also used experience builder to create a user-friendly web map that uses the data from my published web map.&lt;/P&gt;&lt;P&gt;I have attached my first try at a script, but it doesn't work. Any help on how to fix the script would be appreciated.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jun 2026 20:10:37 GMT</pubDate>
    <dc:creator>MatthewAllen</dc:creator>
    <dc:date>2026-06-23T20:10:37Z</dc:date>
    <item>
      <title>Python Script to Auto update Web Map from Arc Pro project</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-auto-update-web-map-from-arc-pro/m-p/1709394#M75296</link>
      <description>&lt;P&gt;I would like to create a python Script to automatically update my web map from my ArcPro project.&lt;/P&gt;&lt;P&gt;I have a ArcPro project that I manually update the web map right now.&lt;/P&gt;&lt;P&gt;I also used experience builder to create a user-friendly web map that uses the data from my published web map.&lt;/P&gt;&lt;P&gt;I have attached my first try at a script, but it doesn't work. Any help on how to fix the script would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2026 20:10:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-auto-update-web-map-from-arc-pro/m-p/1709394#M75296</guid>
      <dc:creator>MatthewAllen</dc:creator>
      <dc:date>2026-06-23T20:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to Auto update Web Map from Arc Pro project</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-auto-update-web-map-from-arc-pro/m-p/1709562#M75301</link>
      <description>&lt;P&gt;1st Script: &lt;SPAN&gt;Double check you are signed in and correct&amp;nbsp;portal connection&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;server&lt;SPAN class=""&gt;.&lt;/SPAN&gt;UploadServiceDefinition(&lt;SPAN class=""&gt;sd&lt;/SPAN&gt;, &lt;SPAN class=""&gt;portal_url&lt;/SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;print(arcpy.GetActivePortalURL())&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Change raise Exception(f"Map '{map_name}' not found.")&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;sddraft = os.path.join(sharing_draft_folder, f"{service_name}.sddraft")&lt;BR /&gt;sd = os.path.join(sharing_draft_folder, f"{service_name}.sd")&lt;/P&gt;&lt;P&gt;print(f"{service_name} published successfully!")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And for the Exception try,&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;except&lt;/SPAN&gt; &lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;"Publishing failed."&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;GetMessages(&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;GetMessages(&lt;/SPAN&gt;&lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;GetMessages(&lt;/SPAN&gt;&lt;SPAN class=""&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;raise&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;2nd script:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;You are missing your drive letter,&amp;nbsp;PROJECT = r"\GISdata\ArcGISPro_Projects\SamplePublishArcPly.aprx", something like,&amp;nbsp;PROJECT = r"&lt;STRONG&gt;C:&lt;/STRONG&gt;\GISdata\ArcGISPro_Projects\SamplePublishArcPly.aprx"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;before &lt;SPAN class=""&gt;C:\&lt;/SPAN&gt;&lt;SPAN class=""&gt;GIS&lt;/SPAN&gt;&lt;SPAN&gt;\&lt;/SPAN&gt;&lt;SPAN class=""&gt;Logs&lt;/SPAN&gt;, add&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;os&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;makedirs(&lt;/SPAN&gt;&lt;SPAN class=""&gt;r"C:\GIS\Logs"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;exist_ok&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;True&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;os&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;makedirs(&lt;/SPAN&gt;&lt;SPAN class=""&gt;OUTPUT_FOLDER&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;exist_ok&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;True&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Error Handling try&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;try&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;except&lt;/SPAN&gt; &lt;SPAN class=""&gt;Exception&lt;/SPAN&gt; &lt;SPAN class=""&gt;as&lt;/SPAN&gt; &lt;SPAN class=""&gt;ex&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;logging&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;error(&lt;/SPAN&gt;&lt;SPAN class=""&gt;ex&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;logging&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;error(&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;GetMessages())&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;raise&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
import os

aprx_path = r"C:\GISdata\ArcGISPro_Projects\SamplePublishArcPly.aprx"

map_name = "SampleAutoPublish"
service_name = "SampleAutoPublish"

portal_url = "https://www.arcgis.com"
username = "xyzx"
password = "yyyy"

sharing_draft_folder = r"C:\GIS\Publishing"

description = "Sample Auto Publish Feature Layer"
tags = "GIS, Caldwell County, Sample"

arcpy.SignInToPortal(portal_url, username, password)

aprx = arcpy.mp.ArcGISProject(aprx_path)

maps = aprx.listMaps(map_name)

if not maps:
    raise Exception(f"Map '{map_name}' not found.")

map_obj = maps[0]

sharing_draft = map_obj.getWebLayerSharingDraft(
    "HOSTING_SERVER",
    "FEATURE",
    service_name
)

sharing_draft.summary = description
sharing_draft.description = description
sharing_draft.tags = tags
sharing_draft.overwriteExistingService = True

os.makedirs(sharing_draft_folder, exist_ok=True)

sddraft = os.path.join(
    sharing_draft_folder,
    f"{service_name}.sddraft"
)

sd = os.path.join(
    sharing_draft_folder,
    f"{service_name}.sd"
)

try:

    print("Creating SDDraft...")
    sharing_draft.exportToSDDraft(sddraft)

    print("Staging service...")
    arcpy.server.StageService(sddraft, sd)

    print("Uploading service...")
    arcpy.server.UploadServiceDefinition(
        sd,
        "HOSTING_SERVER"
    )

    print(f"{service_name} published successfully!")

except Exception:

    print("Publishing failed.")
    print(arcpy.GetMessages(0))
    print(arcpy.GetMessages(1))
    print(arcpy.GetMessages(2))
    raise&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;2nd script:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Also,&amp;nbsp;&lt;SPAN&gt;Double check you are signed in and correct&amp;nbsp;portal connection&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp;&lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;.&lt;SPAN&gt;server&lt;/SPAN&gt;.&lt;SPAN&gt;UploadServiceDefinition(&lt;/SPAN&gt;&lt;SPAN class=""&gt;sd&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;PORTAL&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;print(arcpy.GetActivePortalURL())&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import datetime
import logging

PROJECT = r"C:\GISdata\ArcGISPro_Projects\SamplePublishArcPly.aprx"
MAP_NAME = "SampleAutoPublish"
SERVICE_NAME = "SampleAutoPublish"

OUTPUT_FOLDER = r"C:\GIS\Publishing"
LOG_FOLDER = r"C:\GIS\Logs"

PORTAL = "https://www.arcgis.com"
USERNAME = "your_username"
PASSWORD = "your_password"

os.makedirs(OUTPUT_FOLDER, exist_ok=True)
os.makedirs(LOG_FOLDER, exist_ok=True)

logging.basicConfig(
    filename=os.path.join(LOG_FOLDER, "Publish.log"),
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(message)s"
)

try:

    arcpy.SignInToPortal(PORTAL, USERNAME, PASSWORD)

    aprx = arcpy.mp.ArcGISProject(PROJECT)

    maps = aprx.listMaps(MAP_NAME)

    if not maps:
        raise Exception(f"Map '{MAP_NAME}' not found.")

    m = maps[0]

    sharing_draft = m.getWebLayerSharingDraft(
        "HOSTING_SERVER",
        "FEATURE",
        SERVICE_NAME
    )

    sharing_draft.overwriteExistingService = True

    sddraft = os.path.join(OUTPUT_FOLDER, f"{SERVICE_NAME}.sddraft")
    sd = os.path.join(OUTPUT_FOLDER, f"{SERVICE_NAME}.sd")

    for f in [sddraft, sd]:
        if os.path.exists(f):
            os.remove(f)

    sharing_draft.exportToSDDraft(sddraft)

    arcpy.server.StageService(sddraft, sd)

    arcpy.server.UploadServiceDefinition(
        sd,
        "HOSTING_SERVER"
    )

    logging.info(f"{SERVICE_NAME} successfully overwritten.")

    print(f"Completed: {datetime.datetime.now()}")

except Exception as ex:

    logging.error(str(ex))
    logging.error(arcpy.GetMessages())

    print("Publish failed.")
    print(ex)
    print(arcpy.GetMessages())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2026 15:03:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-auto-update-web-map-from-arc-pro/m-p/1709562#M75301</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2026-06-24T15:03:56Z</dc:date>
    </item>
  </channel>
</rss>

