gdown: Permission denied ... Maybe you need to change permission over 'Anyone with the link'?

I want to download a 16GB zip file on Google Drive using:

gdown https://drive.google.com/uc?id=1InfIal4y7OBMGNUDeldEmDxtD0MrewY8

I have already set the permissions on the file to ``Anyone with the link’’

But I get this error:

Permission denied: https://drive.google.com/uc?id=1InfIal4y7OBMGNUDeldEmDxtD0MrewY8 Maybe you need to change permission over ‘Anyone with the link’?

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 88
  • Comments: 126 (21 by maintainers)

Most upvoted comments

I’ve added a new feature to keep cookies https://github.com/wkentaro/gdown/pull/51. I hope this fixes this issue.

You can try pre-released version of this.

pip install -U --no-cache-dir gdown --pre

by default, cookies is enabled and saved into ~/.cache/gdown/cookies.json. You can disable it by gdown --no-cookies XXX

The solution is to change the permission.

I tried the solution provided by Mehdi and it’s working !

!gdown "YOUR_ID_HERE&confirm=t"

Same problem, upgraded to latest release and I get the following message:

Access denied with the following error:

 	Too many users have viewed or downloaded this file recently. Please
	try accessing the file again later. If the file you are trying to
	access is particularly large or is shared with many people, it may
	take up to 24 hours to be able to view or download the file. If you
	still can't access a file after 24 hours, contact your domain
	administrator. 

You may still be able to access the file from the browser:
%%%URLHERE

Gdown v4.3.0 is out! https://github.com/wkentaro/gdown/releases/tag/v4.3.0 Hope it fixes this issue. (Please request reopening if not)

FYI, you can upgrade gdown by:

pip install --upgrade --no-cache-dir gdown

I tried the solution provided by Mehdi and it’s working !

!gdown "YOUR_ID_HERE&confirm=t"

This also works for me. A very simple way.

I have this issue as well with a 15GB dataset and a 4.3 GB dataset. But when I copy the 4.3GB to my local drive and manually get the link on my copied dataset it works. Can’t make a copy of the 15GB on free drive though.

For reference the datasets im downloading are: https://drive.google.com/file/d/1NrqOLbMa_RwHbG3KIXJFWLnlND2kiIpj/view https://drive.google.com/file/d/15w0q3Nuye2ieu_aUNdTS_FNvoVzM4RMF/view

I was actually able to successfully download both datasets once from the original links but after needing to redo the downloads they no longer work even when uninstalling and reinstalling gdown

pip3 install --upgrade gdown solve my issue

Gdown v4.3.0 is out! https://github.com/wkentaro/gdown/releases/tag/v4.3.0 Hope it fixes this issue. (Please request reopening if not)

FYI, you can upgrade gdown by:

pip install --upgrade --no-cache-dir gdown

Fixed for me as well. Thanks.

Older version gdown also helps.

pip install gdown==4.6.0

I finally solved this issue by using 4.6.0 gdown to download files.

I find if I rm ~/.cache/gdown/cookies.json and then restart my script, things start downloading again. Is your cookie expiring perhaps? I’m good for 1,000 or so files before I get the error.

Thanks for gdown. Very helpful!

I also encountered this problem almost all the time when I want to down big files in Google Drive. And the solutions mentioned above do not work for me as well. Finally, I successfully tried using OAuth 2.0 to generate the tokens to download a big file in Google Drive.

The details can be referred to from this link. So I create a download.sh script, and add the following commands:

ACCESS_TOKEN="Your_Access_Token"

curl -H "Authorization: Bearer ${ACCESS_TOKEN}" https://www.googleapis.com/drive/v3/files/{FILE_ID}?alt=media -o data.tar.gz

Please replace the ACCESS_TOKEN and FILE_ID with yours.

And then, execute the command bash download.sh in a terminal, and everything goes well : )

I want to download a 16GB zip file on Google Drive using:

gdown https://drive.google.com/uc?id=1InfIal4y7OBMGNUDeldEmDxtD0MrewY8

I have already set the permissions on the file to ``Anyone with the link’’

But I get this error:

Permission denied: https://drive.google.com/uc?id=1InfIal4y7OBMGNUDeldEmDxtD0MrewY8 Maybe you need to change permission over ‘Anyone with the link’?

Try this: !pip install --upgrade --no-cache-dir gdown

pip install gdown==4.6.0

actually solved my issue. thanks

Still doesn’t work - I’m hit with the following error message:

Access denied with the following error:

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. 

You may still be able to access the file from the browser:

!gdown “YOUR_ID_HERE&confirm=t”

Worked like a charm. thank you.

Gdown v4.3.0 is out! https://github.com/wkentaro/gdown/releases/tag/v4.3.0 Hope it fixes this issue. (Please request reopening if not)

FYI, you can upgrade gdown by:

pip install --upgrade --no-cache-dir gdown

it solved for me , Thanks

@e96031413 worked like a charm. thanks alot

pip3 install --upgrade gdown solve my issue

Worked for me as well, thank you

I was trying to download a 2GB zip file from my personal google drive and gave me permission denied. I SOLVED the problem by using this command instead: sudo wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt where you must substitute FILEID with your gdrive file ID and FILENAME with the name of the file you want to save.

Source: https://linux.tips/tutorials/download-large-google-drive-files-with-wget-in-terminal

The solution that worked for me is just to make a copy of the file in Google Drive and use that instead. Remember to set permissions to “Anyone with the Link can view”

I’ve just started running into this, but it happens sporadically. For me, there’s no difference between using 4.4.0 and 4.3.0, and there’s no difference between using just the ID or https://drive.google.com/open?id= or https://drive.google.com/uc?id= or https://drive.google.com/u/0/uc?id=.

The affected file ID is 1_gBUGKhs_bponRcgpLlukggWPCR25blF (2.8 MB .tar.gz). I’m using gdown in a GitHub workflow, which had no issues as of 16 days ago, and then there weren’t any workflow runs until 23 hours ago, which started failing. There are multiple jobs within the workflow, and sometimes gdown will work in a few jobs but not in others. The pass/fail number varies.

When I run it locally, it also works a few times and then starts failing for a bit. I haven’t noticed a pattern about timing or consecutive downloads.

Edit: It also happens sporadically with curl -v -L -o ~/fossil.tgz https://drive.google.com/uc?id=1_gBUGKhs_bponRcgpLlukggWPCR25blF, so it’s not specific to gdown. I wonder if anything changed on Google’s side recently to make this more sensitive.

When it fails

  • Request status is 403
  • download.py download function does not enter the if "Content-Disposition" in res.headers: block
  • download.py get_url_from_gdrive_confirmation function is called with an empty contents string argument

Notable headers:

    "Access-Control-Allow-Methods": "GET,HEAD,OPTIONS",
    "Content-Length": "0",
    "Content-Type": "text/html; charset=UTF-8",

When it works

  • Request status is 200
  • download.py download function enters the if "Content-Disposition" in res.headers: block
  • download.py get_url_from_gdrive_confirmation function is not called

Notable headers:

    "Access-Control-Allow-Methods": "GET,OPTIONS",	
    "Content-Type": "application/x-gzip",	
    "Content-Disposition": "attachment;filename=\"fossil-linux-x64-2.13.tar.gz\";filename*=UTF-8''fossil-linux-x64-2.13.tar.gz",	
    "Content-Length": "2915857",	

Gdown v4.3.0 is out! https://github.com/wkentaro/gdown/releases/tag/v4.3.0 Hope it fixes this issue. (Please request reopening if not)

FYI, you can upgrade gdown by:

pip install --upgrade --no-cache-dir gdown

Thanks a lot! FIxed for me!

looks like these method didn’t working now

It works for some causes, the problem is if your file is being accessed a certain number of times a day there’s no way to fix the issue other than using Oauth, Google Drive rate limits file downloads without authentication.

In google colab try this, it solved my issue

!pip install --upgrade --no-cache-dir gdown

Work like a charm 👍

I’ve added a new feature to keep cookies #51. I hope this fixes this issue.

You can try pre-released version of this.

pip install -U --no-cache-dir gdown --pre

by default, cookies is enabled and saved into ~/.cache/gdown/cookies.json. You can disable it by gdown --no-cookies XXX

It works

pip3 install --upgrade gdown solve my issue

This worked for me as well. I just put !pip3 install --upgrade gdownat the beginning of the code (I’m using Google Colab)

I get the same errors. Either:

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.

or:

Too many users have viewed or downloaded this file recently. Please try accessing the file again later. If the file you are trying to access is particularly large or is shared with many people, it may take up to 24 hours to be able to view or download the file. If you still can't access a file after 24 hours, contact your domain administrator.       

Btw it’s not even a public dataset. It’s my own dataset that I uploaded on google drive and nobody has ever downloaded it yet. Not even I. I got the error the first time I tried to download it. The files are accessible through browser, though.

In case you have a folder: gdown --folder --no-cookies --id XXX worked for me

Someone got a solution?, I got same error 😢

I just confirmed it, google drive was glitching out. I didn’t change anything and it now works… I did however get the following error before it worked (I tried re-downloading it twice):

Access denied with the following error:

        Too many users have viewed or downloaded this file recently. Please
        try accessing the file again later. If the file you are trying to
        access is particularly large or is shared with many people, it may
        take up to 24 hours to be able to view or download the file. If you
        still can't access a file after 24 hours, contact your domain
        administrator.

No one (besides myself and the fine folks on this issue that tried to download my file) has been viewing/downloading this file. However, other files that are hosted on the same drive account have been downloaded at full speed a few times over the last couple days (~200GB @ ~75MB/s). Google probably flagged this as suspicious… Is there a way to throttle the download speed?

@grudloff , Got same error here, did you solve it?

I encountered this issue downloading just 3 files from Gdrive, about 2.8 GB or so. The first two worked fine and the permission error popped up for the third file. After that all downloads stopped working.

I had a funny moment today. I got the same issue explained in the first message on the topic. The solution was to reinstall a several times version of gdown and finally install 5.1.0 ver to solve the problem. But this version had this issue when I started searching for the solution 😆

p.s. it is for colab

@vanloc1808 It seems working for me with the latest.

image

Maybe the cookies file is not helping? If so remove it by rm ~/.cache/gdown/cookies.txt

I tried both

gdown --fuzzy 'https://drive.google.com/file/d/1NmGrEJ1uxrrBgf98UCU9SgpgsGEs3sLb/view?usp=drive_link'

and

gdown https://drive.google.com/uc?id=1NmGrEJ1uxrrBgf98UCU9SgpgsGEs3sLb

But it only works for me with gdown==4.6.0

My solution is (same as above more or less)

  1. Click “Make A Copy” on google drive. It will create a copy of the file (either it’s yours or other people’s) to your drive.
  2. Set the permission to “Anyone with the link” as “Viewer”.
  3. Now you can download as usual.

This works for single files or a folder. The problem is that the same error will occur if you are downloading a folder containing too many files. In that case, you can delete the folder and do the above process again, in this way, google will recognize them as different files so it doesn’t err like “Too many users have viewed or downloaded”.

The drawback of this is that it requires manual operation once the error occurs again.

IMO this is related to google drive not gdown so there is no point to do those pip install stuff

pip3 install --upgrade gdown solve my issue

Thx. Solved my problem 😄

After trying multiple different hacks on stackoverflow and on this repo, I failed to get the job done with gdown and had to use a custom python function from a stackoverflow post, which worked like magic.

import requests
def download_file_from_google_drive(id, destination):
    URL = "https://docs.google.com/uc?export=download"

    session = requests.Session()

    response = session.get(URL, params = { 'id' : id }, stream = True)
    token = get_confirm_token(response)

    if token:
        params = { 'id' : id, 'confirm' : token }
        response = session.get(URL, params = params, stream = True)

    save_response_content(response, destination)    

def get_confirm_token(response):
    for key, value in response.cookies.items():
        if key.startswith('download_warning'):
            return value

    return None

def save_response_content(response, destination):
    CHUNK_SIZE = 32768

    with open(destination, "wb") as f:
        for chunk in response.iter_content(CHUNK_SIZE):
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)

if __name__ == "__main__":
    file_id = 'TAKE ID FROM SHAREABLE LINK'
    destination = 'DESTINATION FILE ON YOUR DISK'
    download_file_from_google_drive(file_id, destination) 

Hi All,

I have found a solution that worked for me. I was trying to download a 112MB file from my gdrive which had the appropriate permissions.

image

Following this link gets me to a page like this

image

If I click on the download button I am taken to a security check

image

The link id at this check is the one you want to use with gdown. For example in colab, the following command:

!gdown --id 1iQhpdvoTyuvhxS9pvj4IwXZ-WE2V0dTv

This worked for me, hopefully it helps someone else.

Is gdown --speed 10MB something you’re looking for?

I had a funny moment today. I got the same issue explained in the first message on the topic. The solution was to reinstall a several times version of gdown and finally install 5.1.0 ver to solve the problem. But this version had this issue when I started searching for the solution 😆

p.s. it is for colab

Weirdly this worked for me too. And I was using the default gdown (pip install gdown) on colab using gdown --id ID without a problem until just a few days ago. Thanks!

I had a funny moment today. I got the same issue explained in the first message on the topic. The solution was to reinstall a several times version of gdown and finally install 5.1.0 ver to solve the problem. But this version had this issue when I started searching for the solution 😆

p.s. it is for colab

Yeah this happened to me as well several times (with different versions). I’m not sure why, but changing the version (sometimes to a newer one, sometimes to an older one) seem to work, but always with a different version. Maybe it clears something and allows gdown to download again? I usually try versions 4.6.0, 5.1.0, or the latest (pip install --upgrade gdown). I also remove cookies.txt, and I end up (randomly) with a version that works. Hope this helps

Hi everyone.

I’ve just merged #308 by @pmeier, which adds extra pattern to parse the url to download.

Since I’ve never seen that pattern, I suspect it is a regional issue (I’m accessing from Japan, @pmeier is accessing from Germany). But at least It should help people who have the same issue as him.

@wkentaro see #308. Could you please have a look?

Still not solved 👎🏻

Updated to the latest version (gdown-4.7.1), tried using gdown "id...&confirm=t" and nothing worked for me (47gb zip file):

Access denied with the following error:

 	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.

You may still be able to access the file from the browser:

	 https://drive.google.com/uc?id=...&confirm=t

upd: worked for me after I changed permission type from ‘editor’ back to ‘viewer’

upd2: same command failed on another machine. The ‘cure’ was just to wait for 10 mins and same command worked. idn why

I am trying to download this folder - https://drive.google.com/drive/folders/1NVqQApjO-u881sMTSNubNyn-AogC1q04

But i am getting an error even after trying the solution provided here. I tried like this,

gdown “https://drive.google.com/drive/folders/1NVqQApjO-u881sMTSNubNyn-AogC1q04&confirm=t”.

But this throws up the error - C:\Program Files\Python311\Lib\site-packages\gdown\parse_url.py:44: UserWarning: You specified a Google Drive link that is not the correct link to download a file. You might want to try --fuzzy option or the following url: https://drive.google.com/uc?id=None warnings.warn( Downloading… From: https://drive.google.com/drive/folders/1NVqQApjO-u881sMTSNubNyn-AogC1q04&confirm=t To: C:\1NVqQApjO-u881sMTSNubNyn-AogC1q04&confirm=t 1.69kB [00:00, ?B/s].

Can somebody help me?

pip3 install --upgrade gdown solve my issue

Fixed the issue

Maybe the developers at gdown should take a look at this issue that is persistent from 2 years and not rely on people making workarounds!!!

its literally not gdown’s fault. that being said, maybe adding an option to use the oauth 2.0 token that user provides could potentially solve the problem.

Maybe the developers at gdown should take a look at this issue that is persistent from 2 years and not rely on people making workarounds!!!

While trying to prefetch the file name and other metadata I ran into something similar. However, going to the eventual redirect URL seemed to fix it.

URL = "https://drive.google.com/uc?id="+id+"&authuser=0&export=download&confirm=t"

Adding the "&confirm=t" seemed to help and get straight to the info with Content-Disposition in the header

def fetch_file_metadata_from_google_drive(id):
    URL = "https://drive.google.com/uc?id="+id+"&authuser=0&export=download&confirm=t"
    headers = {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"  # NOQA
    }
    verify=True
    url_origin = URL
    session = requests.Session()
    meta={}
    meta['id']=id
    meta['valid']=False
    meta['filename']=''
    meta['url']=URL
    
    response = session.get(URL,allow_redirects=True, headers=headers, stream = True,verify=verify)
    token = get_confirm_token(response)
    meta['token']=token
    for k in response.headers:
        meta[k] = str(response.headers[k])
        
    if ('Content-Disposition' in response.headers):
        # Get the filename from the response header 'Content-Disposition'
        match = re.search(r'filename="(?P<filename>.+)"', response.headers['Content-Disposition'])
        # Make sure we found the filename field inside Content-Disposition
        if match is None:
            print('\n\nERROR: Unable to retrieve `dest_path` from `file_id`, please set it manually.')
            return meta
        if platform == 'win32':
            # Make it Windows safe, stripping: \/<>:"|?*
            remove_characters = dict((ord(char), None) for char in '\\/<>:"|?*')
        else:
            # Make it macOS and linux safe, stripping: /
            remove_characters = dict((ord(char), None) for char in '/')

        dest_path = match['filename'].translate(remove_characters)
        meta['filename']=dest_path
        meta['valid']=True
        print(json.dumps(meta,indent=4))
    else:
        # Need to redirect with confirmation
        try:
            url = get_url_from_gdrive_confirmation(response.text)
        except RuntimeError as e:
            print("Access denied with the following error:")
            error = "\n".join(textwrap.wrap(str(e)))
            error = indent(error, "\t")
            print("\n", error, "\n", file=sys.stderr)
            print(
                "You may still be able to access the file from the browser:",
                file=sys.stderr,
            )
            print("\n\t", url_origin, "\n", file=sys.stderr)
            meta['browser_url']=url_origin 
            return meta
        print("redirect_url:",id,"-->",url)
        meta['redirect_url']=url        
    return meta

Hello, I used the next code and I hadn’t any problem with my file, it has 29 GB import gdown import time url=‘https://drive.google.com/uc?id=XXXXXXXXXXXXXXX’ output=‘velo.zip’ time.sleep(100) gdown.download(url, output, quiet=False)

I was chugging along nicely for a while, but I now am also getting same error as @grudloff. I was in fact able to pull the file up in a browser and start the download as indicated above. I looked in the gdown cookie and didn’t see any download_warning lines, so evidently we never got the cookie back from them with the additional authorization.

(I have now installed 3.11.1, but was running on 3.11.0 before, I simply inserted a “rm ~/.cache/gdown/cookies.json” every fifty lines. Sorry, it was working so I didn’t want to bother it. 😃. The upgrade doesn’t seem to help on the above error.