I'm trying to extract comments from rows in a Smartsheet sheet using the Smartsheet Python SDK, but I'm encountering several errors, particularly 'AttributeError: 'Sheets' object has no attribute 'get_row_comments'
and 'Attachments' object has no attribute 'list_attachments'
. After some debugging, I realized that the API responses do not contain the expected attributes (like message
or rows
), causing the code to fail.
I have tried multiple combinations, but I still can't get the expected results.
Here’s the code I've been working with:
import smartsheet
Configure your Smartsheet client
access_token = 'your_access_token_here' # Make sure to place your access token here
smartsheet_client = smartsheet.Smartsheet(access_token)
Sheet ID provided
sheet_id = 8165655023931268 # This is the sheet ID
def get_comments_from_sheet(sheet_id):
try:
# Get the sheet
response_sheet = smartsheet_client.Sheets.get_sheet(sheet_id)
# Check if the response contains rows
if hasattr(response_sheet, 'rows'):
rows = response_sheet.rows # Get the rows from the sheet
comments = []
# Iterate over each row and get the comments
for row in rows:
row_id = row.id
try:
# Get the comments for the row using list_comments
response_comments = smartsheet_client.Comments.list_comments(sheet_id, row_id)
for comment in response_comments.data:
comments.append(comment.text) # Store the comment text
except smartsheet.exceptions.SmartsheetException as e:
print(f"Error getting comments for row {row_id}: {e}")
return comments
else:
print("Error: Could not retrieve the rows from the sheet.")
return []
except smartsheet.exceptions.SmartsheetException as e:
print(f"Error retrieving rows from the sheet: {e}")
return []
Call the function
comments = get_comments_from_sheet(sheet_id)
print("Comments:")
for comment in comments:
print(comment)