I have a bit of code that is making a Table View and then updating a field based on a WHERE clause.
as Long as my Service is PUBLIC it works fine... if I lock down to Organization or Owner it does not work. I am using a TOKEN but that still does not work...
I keep getting an error that the table view does not exist which is telling me the arcpy.management.MakeTableView is not working on the secured service.
Why does this not work on a Secured Service with a proper TOKEN
def updateDataFlagValuesToImported():
gis2 = GIS("https://**unspecified**.com/portal", "username", "********")
currenttoken2 = gis2._con.token
print(currenttoken2)
arcpy.env.overwriteOutput = True
updateFlagURL = r"https://**unspecified**.com/env/rest/services/**unspecified**/FeatureServer/0?token=" + currenttoken2
print(updateFlagURL)
whereClause = "FLAG IS NULL"
tableView = "fLyr"
try:
arcpy.management.MakeTableView(updateFlagURL, tableView, whereClause)
except Exception:
# Handle errors accordingly...this is generic
tb = sys.exc_info()[2]
tb_info = traceback.format_tb(tb)[0]
pymsg = 'PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n'
msgs = 'ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n'
print(pymsg)
print(msgs)
arcpy.management.CalculateField(
in_table= "fLyr",
field="FLAG",
expression="'Imported'",
expression_type="PYTHON3",
code_block="",
field_type="TEXT",
enforce_domains="NO_ENFORCE_DOMAINS"
)