<?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: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268530#M67118</link>
    <description>&lt;P&gt;I see you have it set to run whether user logged in or not, so possibly running scheduled task when not logged in.&lt;/P&gt;&lt;P&gt;Not sure if this is your issue, but may be related to this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;docFolder = r"Q:\2023\IMPORTED TO GIS"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only the local drives (C:\) exist when no user is logged in.&amp;nbsp; The mapped drives are user specific, so when nobody is logged in, the Q: drive doesn't exist.&lt;/P&gt;&lt;P&gt;Try using the UNC paths for everything other than local drives and see if it helps.&lt;/P&gt;&lt;P&gt;Also, unless you specifically created it, don't think this path would be valid either:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.env.workspace = r'C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'&lt;/LI-CODE&gt;&lt;P&gt;Normally, would have a username in there:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.env.workspace = r'C:\Users\UserName\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2023 15:13:58 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2023-03-16T15:13:58Z</dc:date>
    <item>
      <title>Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268266#M67110</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Hello all,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I have ArcGIS Pro 3.0, window task scheduler and python 27. I am not expertise with window task scheduler. Please see screenshots and error below. It is working successful when I run python script manually. But when I tried to run window task scheduler,&amp;nbsp;I got error messages. I am not sure what to do. Please kindly assist. Thank you so much in advance.&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexP__4-1678912359486.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65391i6C436C43C429C43E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlexP__4-1678912359486.png" alt="AlexP__4-1678912359486.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexP__3-1678912277055.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65390iB346831CD88F3749/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlexP__3-1678912277055.png" alt="AlexP__3-1678912277055.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ERROR MESSAGES&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexP__1-1678912026620.png" style="width: 750px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65388iD855B8669BD07BC0/image-dimensions/750x30?v=v2" width="750" height="30" role="button" title="AlexP__1-1678912026620.png" alt="AlexP__1-1678912026620.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexP__1-1678912944089.png" style="width: 608px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65393i80BDCE2FEDD0CADF/image-dimensions/608x157?v=v2" width="608" height="157" role="button" title="AlexP__1-1678912944089.png" alt="AlexP__1-1678912944089.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexP__0-1678911899047.png" style="width: 474px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65387iEA2732194F4F12B7/image-dimensions/474x338?v=v2" width="474" height="338" role="button" title="AlexP__0-1678911899047.png" alt="AlexP__0-1678911899047.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexP__0-1678912900829.png" style="width: 513px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65392iC35D9086BE174701/image-dimensions/513x358?v=v2" width="513" height="358" role="button" title="AlexP__0-1678912900829.png" alt="AlexP__0-1678912900829.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;PYTHON SCRIPT CODE&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&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;import arcpy
import csv
import os
from datetime import date
from datetime import datetime

matchTableName = r"ElevationCertificatesAttachmentMatchTable.csv"
docFolder = r"Q:\2023\IMPORTED TO GIS"

matchField = "MatchID"
pathField = "Filename" 

#change this date to the disired value
processFilesAddedOnDate = date.today()

# iterate through each .pdf file in the directory and write a row to the table

       
for (root, dirs, files) in os.walk(docFolder):
    workingFolder = root
    matchTableNamePath = os.path.join(root, matchTableName)
    # create a new Match Table csv file
    if os.path.exists(matchTableNamePath):
        os.remove(matchTableNamePath)
    writer = csv.writer(open(matchTableNamePath, "w", newline=''), delimiter=",")
    # write a header row (the table will have two columns: ParcelID and Picture)
    writer.writerow([matchField, pathField, 'fullPath'])
    for f in files:
        
        if '.pdf' in f:
            #if datetime.strptime(os.path.getctime(os.path.join(root, f)),"%m/%d/%Y") &amp;gt;= processFilesAddedOnDate:
            if date.fromtimestamp(os.path.getctime(os.path.join(root, f))) &amp;gt;= processFilesAddedOnDate:
                
                #print(processFilesAddedOnDate)
                #print(date.fromtimestamp(os.path.getctime(os.path.join(root, f))))
                fileNameToAddress = f.replace(".pdf", "")
                fileNameToAddress = fileNameToAddress.replace("  ", " ");
                fileNameToAddress = fileNameToAddress.replace("nw", "NW")
                try:
                    firstPartUntilNW = fileNameToAddress.split("NW")[0].strip().split(" ")
                    restAfterNW = fileNameToAddress.split("NW")[1].strip()
                    #print(firstPartUntilNW, len(firstPartUntilNW))
                    #print(restAfterNW)
                    fileNameToAddressWithNoPermitNumber = ""
                    if len(firstPartUntilNW) == 2:
                        fileNameToAddressWithNoPermitNumber = firstPartUntilNW[1]+" NW "+restAfterNW
                    if len(firstPartUntilNW)== 1:
                        fileNameToAddressWithNoPermitNumber = firstPartUntilNW[0]+" NW "+restAfterNW
                    #print(fileNameToAddressWithNoPermitNumber)
                    writer.writerow((fileNameToAddressWithNoPermitNumber,f, os.path.join(root, f)))
                except:
                    continue
      
    del writer

    # Set the workspace environment and run add attachment
    arcpy.env.workspace = r'C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'

    arcpy.management.AddAttachments('sde.TEST.TEST', 'ADDR', matchTableNamePath, "MatchID", "Filename", workingFolder)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 20:43:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268266#M67110</guid>
      <dc:creator>AlexP_</dc:creator>
      <dc:date>2023-03-15T20:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268284#M67111</link>
      <description>&lt;P&gt;Python 2.7 works with ArcMap and python 3.x (depends on Pro version) works with Pro.&amp;nbsp; I do not think this is the issue as the path that I can see looks like it is for Pro python.&lt;/P&gt;&lt;P&gt;Was this code originally run for ArcMap and you are trying to migrate it to Pro?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 21:13:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268284#M67111</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2023-03-15T21:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268292#M67112</link>
      <description>&lt;P&gt;Hi Alex,&lt;/P&gt;&lt;P data-unlink="true"&gt;I never used WinTS myself but just got curious and checked your screenshots and did not see any explicit error message, except for the one that returned code 2147942402. So, I looked that up and apparently it has something to do with the path of the executable that you pass. Based on what I read you need to make sure all the paths really exist and there is no typo there. In "C:\Program Files\ArcGIS\Pro\bin\Python\envs\... " or the part 'add arguments (optional)' that you wrote your script's name. Make sure to enter the full path to your script there.&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;Check this &lt;A href="https://stackoverflow.com/questions/11865369" target="_self"&gt;link&lt;/A&gt;. Not the exact problem but might worth checking. Sorry that's all I've got for now. Hopefully you will find an answer soon.&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 21:29:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268292#M67112</guid>
      <dc:creator>Mahdi_Ch</dc:creator>
      <dc:date>2023-03-15T21:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268530#M67118</link>
      <description>&lt;P&gt;I see you have it set to run whether user logged in or not, so possibly running scheduled task when not logged in.&lt;/P&gt;&lt;P&gt;Not sure if this is your issue, but may be related to this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;docFolder = r"Q:\2023\IMPORTED TO GIS"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only the local drives (C:\) exist when no user is logged in.&amp;nbsp; The mapped drives are user specific, so when nobody is logged in, the Q: drive doesn't exist.&lt;/P&gt;&lt;P&gt;Try using the UNC paths for everything other than local drives and see if it helps.&lt;/P&gt;&lt;P&gt;Also, unless you specifically created it, don't think this path would be valid either:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.env.workspace = r'C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'&lt;/LI-CODE&gt;&lt;P&gt;Normally, would have a username in there:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.env.workspace = r'C:\Users\UserName\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 15:13:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268530#M67118</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-03-16T15:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268555#M67122</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Thank you for your reply. the add argument is already add full path. by full path, I have different letter than C: and it is already set up map network. I am gonna try using UNC as per&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 16:09:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268555#M67122</guid>
      <dc:creator>AlexP_</dc:creator>
      <dc:date>2023-03-16T16:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268566#M67123</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;Thank you for your reply. Do I also need to input UNC path on add argument optional since it is not letter C:?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 16:27:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268566#M67123</guid>
      <dc:creator>AlexP_</dc:creator>
      <dc:date>2023-03-16T16:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268572#M67125</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please correct me if I am wrong, but I thought&amp;nbsp;when installing Pro for the machine (all users), that puts the installed directory in the ProgramFiles and when installing in "User Only" mode, that will be created under the User directory.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 16:35:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268572#M67125</guid>
      <dc:creator>Mahdi_Ch</dc:creator>
      <dc:date>2023-03-16T16:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268584#M67126</link>
      <description>&lt;P&gt;I don't see reference to ProgramFiles in the script.&amp;nbsp; However, I have only installed for the machine (all users), it then keeps a separate app settings folder (hidden) for each user logged in when they run Pro like so:&lt;/P&gt;&lt;P&gt;C:\Users\UserName\AppData\Roaming\Esri\ArcGISPro\Favorites&lt;/P&gt;&lt;P&gt;I've never tried "User Only" mode, so not sure how/where it stores the app setting in this case.&lt;/P&gt;&lt;P&gt;You should be able to check your computer and see if there is an AppData folder with Pro settings in the root level of the users directory, or if you need to open specific user folder first.&lt;/P&gt;&lt;P&gt;C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 16:51:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268584#M67126</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-03-16T16:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when run Window Task Scheduler - Python: Last Run Result (0x2)</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268607#M67128</link>
      <description>&lt;P&gt;"ANY" paths that are not on the local drive will need to be UNC for it to run as scheduled task when user not logged in.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 17:08:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-run-window-task-scheduler-python/m-p/1268607#M67128</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-03-16T17:08:31Z</dc:date>
    </item>
  </channel>
</rss>

