I am using the Python SDK API Call update rows in a Smartsheet sheet. We are issuing simultaneous API calls, and hence some requests are failing with error:
Process finished with exit code 0
{"response": {"statusCode": 500, "reason": "Internal Server Error", "content": {"errorCode": 4004, "message": "Request failed because sheetId ##### is currently being updated by another request that uses the same access token. Please retry your request once the previous request has completed.", "refId": "####"}}}
Here is the code that's causing this error when running multiple times simultaneously to update different rows in the same sheet:
import smartsheet
SMARTSHEET_ACCESS_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXX"
smartsheet_client = smartsheet.Smartsheet(SMARTSHEET_ACCESS_TOKEN)
sheet = smartsheet_client.Sheets.get_sheet('XXXXXXXXXXXXXX')
column_map = {}
for column in sheet.columns:
column_map[column.title] = column.id
# print(column_map)
row_map = {}
i = 0
# counter
for rows in sheet.rows:
row_map[i] = rows.id
i = i + 1
# print(row_map)
new_cell = smartsheet_client.models.Cell()
# Update column Remaining
error = 0
new_cell.column_id = column_map['Last End Time']
new_cell.value = '02/23/2023 12:13:57 AM'
new_cell.strict = False
get_row = smartsheet.models.Row()
get_row.id = row_map[int(5) - 1]
get_row.cells.append(new_cell)
api_response = smartsheet_client.Sheets.update_rows('xxxxxxxxxxxxxxxxxxxx', [get_row])
print(api_response)
How can we avoid getting this error if we want to use the Python SDK to update multiple rows in a sheet?
This is code to update a particular cell in the row. We will be calling this simultaneously to update different rows.