Error: TypeError: sequence size must match size of the row

Error Message

When adding rows to a feature class or table using the InsertCursor ArcPy function, the following error is returned:

"TypeError: sequence size must match size of the row."


The cause for this error is usually either related to field matching or syntax errors.

1. Field matching error
When setting up the values to be inserted into the feature class or table, the fields must match the defined fields within the cursor. This includes setting them in the correct order and ensuring that the field types and lengths match the data to be inserted.

In this example, the row values being inserted do not match up correctly with the InsertCursor fields:

[O-Image] Code Example
2. Python syntax error
There are many possible syntax errors, but this error usually relates to the way the data list is set up.

In this example, the XY coordinates are in a tuple that is not formatted correctly within the list to create the geometry:

[O-Image] Code Example 2

Solution or Workaround

Check to ensure that the row values being inserted line up with the InsertCursor fields, and the geometry lists are properly formatted.

1. Solution to field matching error
Set only the necessary fields required for the data being inserted.

[O-Image] Code Example 3
2. Solution to syntax error
When using the SHAPE@XY token to create a single point, a tuple with a single value is required. To be properly recognized, a single value tuple should be written with a trailing comma.

[O-Image] Code Example 4

Breaking out SHAPE@X and SHAPE@Y allows a tuple with a single value to be avoided.

[O-Image] Code Example 5

Related Information