error with UpdateCursor in Jupyter notebook

1560
16
03-18-2021 05:24 AM
GrantBenn1
New Contributor III

Hi,

I am new to Jupyter notebooks in AGOL. I am trying to develop a script which updates a field in  a hosted feature layer based on what has been entered in other fields. I am getting an error (code 400) pointing to the "for row in cursor:" line. This script works perfectly on my desktop machine. Any ideas as to what might be wrong? Here is what I am seeing in Notebook.

GrantBenn1_0-1616070232033.png

Thanks,

Grant

 

0 Kudos
16 Replies
GrantBenn1
New Contributor III

Hi Dan,

Its a hosted feature layer in AGOL. I could share the rest endpoint address with you via Private Message?

Thanks,

Grant

0 Kudos
GrantBenn1
New Contributor III

Hi Dan,

Tested using the feature class properties (featureType and shapeType) and I got results so it is a feature class.

Thanks,

Grant

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

In the last incarnation of your script you had print statements, are any printing? 

UpdateCursor—ArcGIS Pro | Documentation

there are warnings about what is needed if the data are versioned etc


... sort of retired...
0 Kudos
GrantBenn1
New Contributor III

Using the code below the only print statements that print are print('in') and the last print statement print(VehAvailMain_Score).

Versioning - its an AGOL hosted feature layer. How do you know whether these are versioned? Editing is enabled, as is "Keep track of created and updated features" and "Keep track of who created and last updated features". The last two are suggestive of versioning.

 

from arcgis.gis import GIS
gis = GIS("home")
import arcpy, arcpy.da, requests, json

inputFC = 'https://services8.arcgis.com/eDOP1zOdWfMRGgMh/arcgis/rest/services/????/FeatureServer/0'
TableFields_VehicleAvailability = ['MajorPumpActualNum','MediumPumpActualNum']#,'FireEnginesActualNum','WaterTankersActualNum','UrbanPumpersActualNum','FoamTendersActualNum','VeldFireVehActualNum','AerialFireActualNum','CommUnitsActualNum','RapidUnitsActualNum','FuelTendersActualNum','CrewBusesActualNum','FireBoatsActualNum','VehReplacePolicy','VehAvailMainScore']#,'VehAvailBonusScore','VehAvailCombScore']

VehAvailMain_Score = 0
VehAvailBonus_Score = 0

#calculate classification score for Vehicle Availability
with arcpy.da.UpdateCursor(inputFC, TableFields_VehicleAvailability) as cursor:
    print('in')
    for row in cursor:
        print('in2')
        VehAvailMain_Score = 0
        VehAvailBonus_Score = 0
        if (row[0] > 0 or row[1] > 0): #Major and Medium Pumps
            VehAvailMain_Score += 1# VehAvailMain_Score + 1
            print('in3')
#        if row[2] > 0: #Fire Engines
#            VehAvailMain_Score = VehAvailMain_Score + 1
#        if row[3] > 0: #Water Tankers
#            VehAvailMain_Score = VehAvailMain_Score + 1
#        if row[6] > 0: #Veld Fire Vehicles
#            VehAvailMain_Score = VehAvailMain_Score + 1
#        if (row[13] == 'Yes' or row[13] == 'No'): #vehicle replacement policy because always either Yes or No
#            row[14] = VehAvailMain_Score #VehAvailMainScore
        cursor.updateRow(row)
del cursor
print(VehAvailMain_Score)

 

0 Kudos
GrantBenn1
New Contributor III

Hi Dan,

Made a little progress. I adjusted the cursor from an UpdateCursor to a SearchCursor and removed cursor.updateRow(row). The script then successfully runs and completes with the print statements reporting as would be expected.

So this makes me think that there is an issue with the edit settings or sharing of the hosted feature layer? although the user running the script owns the hosted feature layer so sharing shouldn't be the issue. Any idea what settings and sharing are required for the hosted feature layer for it to be editable in this manner? 

So I adjusted the settings so that only "Enable Editing" is ticked on and only "Update" and "Attributes only" is allowed. The UpdateCursor was then reinstated in the script. The script runs for a few minutes and then the Notebook returns the following message:

GrantBenn1_0-1616425252658.png

 

 

 

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

No clue.  This may be a Tech Support issue now


... sort of retired...
0 Kudos
GrantBenn1
New Contributor III

Hi Dan,

Thanks a lot for the help. I have contacted our local ESRI office.

Regards,

Grant

0 Kudos