Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

I have a script which uses the package pygsheets to upload a dataframe to Google sheets. If the dataframe is empty, the following error appears:

InvalidArgumentValue: provide either cells or values, not both

So, I have been trying to use a try-except structure to pass when the dataframe is empty, but raising an exception if any other error happens. The code is the following:

try:

    pygsheets code

except InvalidArgumentValue:

    pass

except:

    raise Exception

However, when I try to execute the lines above, it throws me the following errors:

NameError: name 'InvalidArgumentValue' is not defined

1 Answer

0 votes
by (25.1k points)

The issue is that you have not imported InvalidArgumentValue you have only imported the pygsheets module.

This could be solved by either : 

1.Using the exception like pygsheets.InvalidArgumentValue, or

2. Importing thr exception properly like from pygsheets import InvalidArgumentValue.

You can code to look like this:

try:

pygsheets code

except pygsheets.InvalidArgumentValue:

    pass

except:

    raise Exception

Browse Categories

...