<?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: User Authentication in hosted .pyt toolbox / geoprocessing tool in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1670485#M11803</link>
    <description>&lt;P&gt;When you run this in ArcGIS Pro Geoprocessing pane the toolbox script is pulling your credentials from your ArcGIS Pro login by using: gis = GIS("home") . I'm not familiar with the login functionality on the Enterprise side when passing "home". You may need to enter user credentials to run in enterprise:&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/guide/working-with-different-authentication-schemes/#:~:text=in%20as%20arcgis_python-,Connect%20to%20ArcGIS%20Enterprise%20using%20a%20built%2Din%20account,-print(%22Portal" target="_blank"&gt;https://developers.arcgis.com/python/latest/guide/working-with-different-authentication-schemes/#:~:text=in%20as%20arcgis_python-,Connect%20to%20ArcGIS%20Enterprise%20using%20a%20built%2Din%20account,-print(%22Portal&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Do you happen to have MFA setup in your Enterprise?&lt;/P&gt;</description>
    <pubDate>Thu, 04 Dec 2025 15:35:02 GMT</pubDate>
    <dc:creator>BenCapell_NWTF10</dc:creator>
    <dc:date>2025-12-04T15:35:02Z</dc:date>
    <item>
      <title>User Authentication in hosted .pyt toolbox / geoprocessing tool</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1670293#M11802</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I have a .pyt toolbox which runs correctly in the ArcGIS Pro 3.5 environment but fails when the tool is hosted on ArcGIS Enterprise 11.3.&amp;nbsp; The tool uses arcpy and the arcgis api for python to retrieve a hosted webmap, included layers and hosted layout, all of which are available to all users within the organization.&lt;/P&gt;&lt;P&gt;The tool uses&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;gis = GIS("home")&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;when run inside of ArcGIS Pro.&amp;nbsp; However,&amp;nbsp; when run in a hosted environment, I receive the the following errors:&lt;BR /&gt;&lt;BR /&gt;{"error":{"code":499,"message":"Token Required","details":[]}}&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;RuntimeError: Failed to create layer from service at &lt;A href="https://portal_url.com/gisweb/rest/services/Hosted/feature_layer/FeatureServer/1.\n&amp;quot;" target="_blank"&gt;https://portal_url.com/gisweb/rest/services/Hosted/feature_layer/FeatureServer/1.\n"&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I assume this is related to user authentication/credentials, but I cannot figure out how to properly pass credentials when hosting.&amp;nbsp; Should I be using keyring to do so?&amp;nbsp; If so, what is the proper way of setting it up?&amp;nbsp; Does the .pyt toolbox need to be run from the server machine in ArcGIS Pro, or can it be run on my local computer?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Below is the execute() portion of the .pyt toolbox.&amp;nbsp; Any insights you may have into how to properly pass API credentials when hosting a .pyt toolbox on enterprise would be greatly appreciated.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"""   
    def execute(self, parameters, messages):

        parcel_apn = parameters[0].valueAsText
        output_pdf = parameters[1].valueAsText

        web_map_id = "a4373271ba30412939sh23201h8h282"
        layout_id = "btheh82hek930jj3932429je9302030"

        attributes = ["SHAPE@", "apn", "property_name"]

        parcels = [parcel_apn]

        gis = GIS("home")
        

        webmap_item = gis.content.get(web_map_id)
        arcpy.AddMessage(webmap_item)
        web_map_json = webmap_item.get_data()
        arcpy.AddMessage("")
        arcpy.AddMessage("")
        pretty_json = json.dumps(web_map_json, indent=4)
        arcpy.AddMessage(pretty_json)
        web_map_json.update(json.loads('''{"mapOptions" : { "extent" : {  "xmin":6787761,  "ymin":2073010,  "xmax":6787762,  "ymax":2073011,  "spatialReference" : {   "wkid" : 6418  } }}}'''))

        pagx_path = os.path.join(arcpy.env.scratchFolder, "Report.pagx")
        layout_item = gis.content.get(layout_id)
        layout_item.download(pagx_path)

        result = arcpy.mp.ConvertWebMapToArcGISProject(json.dumps(web_map_json), template_pagx=fr"{pagx_path}\Property_Report_1.pagx")
        
        aprx = result.ArcGISProject

        map = aprx.listMaps("Web Map")[0]

        layer = map.listLayers("Properties")[0]

        layout = aprx.listLayouts("Property Report")[0]

        map_frame = layout.listElements("MAPFRAME_ELEMENT", "Property Map Frame")[0]
        arcpy.AddMessage(map_frame.name)

        property_name_text = layout.listElements("TEXT_ELEMENT", "Property Name")[0]
        apn_text = layout.listElements("TEXT_ELEMENT", "APN")[0]

        for parcel in parcels:
            
            arcpy.management.SelectLayerByAttribute(layer, "NEW_SELECTION", where_clause=f"apn = '{parcel}'") 
            
            with arcpy.da.SearchCursor(layer, attributes, where_clause=f"apn = '{parcel}'") as cursor:
                for row in cursor:
                    extent = row[0].extent
                    apn = row[1]
                    property_name = row[2]

            # Get Parcel Layer Extent and Pad it by 20-Percent in the Active Map Frame

            pad = 0.20
            
            width_pad = extent.width * pad
            height_pad = extent.height * pad
            
            new_xmin = (extent.XMin - width_pad)
            new_xmax = (extent.XMax + width_pad)
            new_ymin = (extent.YMin - height_pad)
            new_ymax = (extent.YMax + height_pad)
            
            padded_extent = arcpy.Extent(new_xmin, new_ymin, new_xmax, new_ymax, spatial_reference=extent.spatialReference)

            map_frame.camera.setExtent(padded_extent)

            property_name_text.text = f"{property_name}"
            apn_text.text = f"APN: {apn}"
            layer.definitionQuery = f"APN = '{parcel}'"

            layout.exportToPDF(output_pdf)
            return
"""&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 03 Dec 2025 20:31:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1670293#M11802</guid>
      <dc:creator>BlakeFulkerson</dc:creator>
      <dc:date>2025-12-03T20:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: User Authentication in hosted .pyt toolbox / geoprocessing tool</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1670485#M11803</link>
      <description>&lt;P&gt;When you run this in ArcGIS Pro Geoprocessing pane the toolbox script is pulling your credentials from your ArcGIS Pro login by using: gis = GIS("home") . I'm not familiar with the login functionality on the Enterprise side when passing "home". You may need to enter user credentials to run in enterprise:&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/guide/working-with-different-authentication-schemes/#:~:text=in%20as%20arcgis_python-,Connect%20to%20ArcGIS%20Enterprise%20using%20a%20built%2Din%20account,-print(%22Portal" target="_blank"&gt;https://developers.arcgis.com/python/latest/guide/working-with-different-authentication-schemes/#:~:text=in%20as%20arcgis_python-,Connect%20to%20ArcGIS%20Enterprise%20using%20a%20built%2Din%20account,-print(%22Portal&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Do you happen to have MFA setup in your Enterprise?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Dec 2025 15:35:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1670485#M11803</guid>
      <dc:creator>BenCapell_NWTF10</dc:creator>
      <dc:date>2025-12-04T15:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: User Authentication in hosted .pyt toolbox / geoprocessing tool</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1670734#M11805</link>
      <description>&lt;P&gt;Hi Ben, we do not have MFA setup in our Enterprise.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Dec 2025 23:49:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1670734#M11805</guid>
      <dc:creator>BlakeFulkerson</dc:creator>
      <dc:date>2025-12-04T23:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: User Authentication in hosted .pyt toolbox / geoprocessing tool</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1672305#M11812</link>
      <description>&lt;P&gt;Ok&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/932599"&gt;@BlakeFulkerson&lt;/a&gt;&amp;nbsp;does the code at the link below work for you after customizing to make your portal url, username, and password?&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/latest/guide/working-with-different-authentication-schemes/#:~:text=print(%22Portal%20for%20ArcGIS%20as%20a%20built%20in%20user%22)%0Agis%20%3D%20GIS(%22https%3A//portalname.domain.com/webadapter_name%22%2C%20%22sharinguser%22%2C%20%22password%22)%0Aprint(%22Logged%20in%20as%3A%20%22%20%2B%20gis.properties.user.username" target="_blank"&gt;https://developers.arcgis.com/python/latest/guide/working-with-different-authentication-schemes/#:~:text=print(%22Portal%20for%20ArcGIS%20as%20a%20built%20in%20user%22)%0Agis%20%3D%20GIS(%22https%3A//portalname.domain.com/webadapter_name%22%2C%20%22sharinguser%22%2C%20%22password%22)%0Aprint(%22Logged%20in%20as%3A%20%22%20%2B%20gis.properties.user.username&lt;/A&gt;)&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2025 15:04:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/user-authentication-in-hosted-pyt-toolbox/m-p/1672305#M11812</guid>
      <dc:creator>BenCapell_NWTF10</dc:creator>
      <dc:date>2025-12-11T15:04:19Z</dc:date>
    </item>
  </channel>
</rss>

