In migrating from Python 2.x to 3.x, we had a process that emails water accounts that are unable to be geocoded and added to our meter feature class. There was no change to the schema, but recently we had the below failure. The field still exists named 'MunisAccount' in the NewAccountsGeocoded feature class.
Error received:
Row: Field MunisAccount does not exist
arcpy.MakeFeatureLayer_management("D:\\WorkSpace\\Water\\Workspace.gdb\\NewAccountsGeocoded", "NewAccountsGeocoded_Layer", "", "", "")
arcpy.SelectLayerByAttribute_management("NewAccountsGeocoded_Layer", "NEW_SELECTION", "Status NOT IN ( 'M', 'T')")
for row in arcpy.SearchCursor("NewAccountsGeocoded_Layer"):
print (row.MunisAccount, row.ARC_Single_Line_Input)
arcpy.AddMessage("Water_ID_Updates Failed...{0}".format('\n'))
txtFile.write("Water_ID_Updates Failed...{0}".format('\n'))
txtFile.write("{0}{1}".format(arcpy.GetMessages(), '\n'))
HOST = "server.host.com"
SUBJECT = "Report: Unable to Add UB Accounts to GIS Accounts"
TO = "brian@email.com"
FROM = "Water Accounts<email@email.com>"
text = "The following UB Account was not able to be imported into GIS WtrAccounts. Please see if there is an error in UB or if the address exists in COH Address GIS feature class. \n " + "UB Account: "+str(row.MunisAccount) + " | UB Address: "+str(row.ARC_Single_Line_Input)+"\n"
BODY = "From: {1}{0}To: {2}{0}Subject: {3}{0}{0}{4}".format('\r\n', FROM, TO, SUBJECT, text)
server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], BODY)
server.quit()