<?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: Script tool fails after first execution in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/script-tool-fails-after-first-execution/m-p/1049119#M60845</link>
    <description>&lt;P&gt;Hi Fred,&lt;/P&gt;&lt;P&gt;i am also getting similar error, did you find any workaround for this?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 20 Apr 2021 14:18:27 GMT</pubDate>
    <dc:creator>PugazhendhiNatarajan</dc:creator>
    <dc:date>2021-04-20T14:18:27Z</dc:date>
    <item>
      <title>Script tool fails after first execution</title>
      <link>https://community.esri.com/t5/python-questions/script-tool-fails-after-first-execution/m-p/10158#M887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Got an odd one... I feel like I've come across something similar before but it's got me stumped right now.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quick Summary:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The script tool runs successfully outside of ArcMap/Catalog via python CLI&lt;/LI&gt;&lt;LI&gt;The script tool runs successfully the FIRST time run from the toolbox inside ArcMap/ArcCatalog&lt;/LI&gt;&lt;LI&gt;The script tool FAILS every time after the first until ArcMap/ArcCatalog is closed and restarted&lt;/LI&gt;&lt;LI&gt;The function in the script tool runs successfully if called multiple times from a second script tool during the same execution but then fails with the same pattern when run consecutively.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;The failure is a critical level exception exiting the script:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="font-size: 11px;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "D:\support\arcgis\msal\doauth.py", line 21, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; result = get_token()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "D:\support\arcgis\msal\doauth.py", line 14, in get_token&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; client_credential=""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\msal\application.py", line 239, in __init__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; self.http_client, validate_authority=validate_authority)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\msal\authority.py", line 85, in __init__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; self.http_client)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\msal\authority.py", line 142, in tenant_discovery&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; resp = http_client.get(tenant_discovery_endpoint, **kwargs)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\requests\sessions.py", line 543, in get&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; return self.request('GET', url, **kwargs)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\requests\sessions.py", line 516, in request&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; prep = self.prepare_request(req)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\requests\sessions.py", line 455, in prepare_request&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; headers=merge_setting(request.headers, self.headers, dict_class=CaseInsensitiveDict),&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\requests\sessions.py", line 69, in merge_setting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; merged_setting = dict_class(to_key_val_list(session_setting))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\requests\structures.py", line 46, in __init__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; self.update(data, **kwargs)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\Lib\_abcoll.py", line 564, in update&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; if isinstance(other, Mapping):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\Lib\abc.py", line 144, in __instancecheck__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; return cls.__subclasscheck__(subtype)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\Lib\abc.py", line 180, in __subclasscheck__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; if issubclass(subclass, scls):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\Lib\abc.py", line 180, in __subclasscheck__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; if issubclass(subclass, scls):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; File "C:\Python27\ArcGIS10.6\lib\site-packages\typing.py", line 1410, in __subclasscheck__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt; return super(GenericMeta, self).__subclasscheck__(cls)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 11px;"&gt;TypeError: super() argument 1 must be type, not None&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Details:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The script tool integrates data between a feature class and an external API behind an AzureAD authentication.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've installed the &lt;A href="https://github.com/AzureAD/microsoft-authentication-library-for-python"&gt;official Microsoft library&lt;/A&gt;:&amp;nbsp;&lt;/P&gt;&lt;P&gt;c:\Python27\ArcGIS10.6\Scripts\pip.exe install msal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The failure is not in the actual call for an authorization token but simply in the init constructor of the 'AD App' class so I'm able to strip it down to a very basic example which is attached in the zip file:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. doauth.py - script file with function that initializes the 'AD App' and returns a true/false if the app class is created&lt;/P&gt;&lt;P&gt;2. doauth2.py - script file that calls the 'create app' function inside doauth.py twice in a row&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;This was an attempt to see if it's something with multiple instances of the app class being created or if it's something specific with how ArcMap/Catalog are running the script itself.... appears to be the latter&lt;/P&gt;&lt;P&gt;3. toolbox.tbx - toolbox with both scripts attached as tools&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To repo:&lt;/P&gt;&lt;P&gt;1. install msal (see above)&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. CLI tests (execution is successful, no exceptions throw, simple text output returned)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;c:\Python27\ArcGIS10.6\Scripts\python.exe doauth.py&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;c:\Python27\ArcGIS10.6\Scripts\python.exe doauth2.py&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;3. Open ArcCatalog&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Browse to toolbox&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Execute DoAuth tool - success, close window&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Execute DoAuth tool - fail&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;Close ArcCatalog&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Repeat&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Any thoughts?&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thanks in advance&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Nov 2020 23:29:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tool-fails-after-first-execution/m-p/10158#M887</guid>
      <dc:creator>FredSpataro</dc:creator>
      <dc:date>2020-11-03T23:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: Script tool fails after first execution</title>
      <link>https://community.esri.com/t5/python-questions/script-tool-fails-after-first-execution/m-p/1049119#M60845</link>
      <description>&lt;P&gt;Hi Fred,&lt;/P&gt;&lt;P&gt;i am also getting similar error, did you find any workaround for this?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:18:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tool-fails-after-first-execution/m-p/1049119#M60845</guid>
      <dc:creator>PugazhendhiNatarajan</dc:creator>
      <dc:date>2021-04-20T14:18:27Z</dc:date>
    </item>
  </channel>
</rss>

