wkentaro / gdown

Google Drive Public File Downloader when Curl/Wget Fails
MIT License
4.05k stars 342 forks source link

`gdown.download` should raise an exception if access is denied #276

Open nutjob4life opened 11 months ago

nutjob4life commented 11 months ago

Provide environment information

What OS are you using?

macOS 13.4

Describe the Bug

In some deeply embedded code, an autonomous system calls

fd, fn = tempfile.mkstemp('.xlsx')
os.close(fd)
gdown.download(id=file_identifier, output=fn, quiet=True, use_cookies=False, format='xlsx')

and an unexpected error occurs later in the system when the supposedly downloaded file is read:

sheet = pandas.read_excel(fn)

with the error:

ValueError: Excel file format cannot be determined, you must specify an engine manually

The problem being that the file fn is actually empty. The real error is:

Cannot retrieve the public link of the file. You may need to change the permission to 'Anyone with the link', or have had many accesses. 

We expected gdown.download to raise an exception on error.

Expected Behavior

An exception to be raised on exceptional conditions.

Alternatively, the docstring should indicate how the return value is used to indicate exceptional conditions.

To Reproduce

  1. Create a file in GDrive and ensure it's not public
  2. gdown.download that file
  3. See if an exception is raised

The workaround is to do what gdown.cli does: check the return value and if it's None, manually raise an exception.

Otherwise, thanks so much for gdown! It's really quite superb otherwise 😇

m-pektas commented 5 months ago

I don't understand, there is no new release but I got this error today. I fixed it downgrading the version to 4.6.0.

iccha-k commented 1 month ago

It woked, Thank you @m-pektas