0

I tried to remove the worksheet in Google docs file. I am using Pygsheets to perform this process. There's only one sheet in that file. So we can't remove the sheet. so it will throw the Error. How i handle it Separately. Below is i tried something. but its not working

def deleteWorksheets(file_name=None, sheet_name=None):
    try:
        sheet = client.open(file_name)
        delete_worksheet = sheet.worksheet_by_title(sheet_name)
        sheet.del_worksheet(delete_worksheet)
    except urllib.error.HTTPError:
        print("You can't remove")

Below error is shown. How to handle it Separately .

<HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/ returned 
"Invalid requests[0].deleteSheet: You can't remove all the sheets in a document.">

1 Answers1

0

I'm not sure whether the issue is the error being thrown is not being caught, but if it is, you need to make sure that urllib.error.HTTPError is the actual error that is being thrown. As lots of libraries will throw a HTTPError, and you may be trying to catch a different HTTPError.

It is difficult to know what error could be thrown without knowing where client is from.