Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alexklwong opened this issue Mar 25, 2020 · 132 comments · Fixed by #308
Open
Labels
bug for issue

Comments

@alexklwong
Copy 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'?

@mrlzla
Copy link

mrlzla commented Mar 25, 2020

The same error

@zenithfang
Copy link

same error

@wkentaro
Copy link
Owner

wkentaro commented Mar 31, 2020

Maybe the same issue as #26.

I found this happens with large data + many access (e.g., public dataset) #42. However, I have no idea how to fix this.

If they are the same issue, there's no solution at the moment from gdown side.

@Rmao99
Copy link

Rmao99 commented Mar 31, 2020

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

@wkentaro
Copy link
Owner

wkentaro commented Mar 31, 2020

@Rmao99 Thanks for the information. That behavior makes sense if that's the issue of Google-Drive's side. It seems they restrict access from the command-line for data with many access (e.g., public dataset).

@wkentaro
Copy link
Owner

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

@Jackie-LJQ
Copy link

Jackie-LJQ commented May 5, 2020

I have the same issue. I tried the above version, not fix.

@whulixiya
Copy link

I met the same error when I try to download many big files from my google drive, have anyone fixed it?

@carlmalamud
Copy link

carlmalamud commented Jun 3, 2020

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!

@wkentaro
Copy link
Owner

wkentaro commented Jun 3, 2020

@carlmalamud Thanks for info. Do you have any sharable links to reproduce this?

@whulixiya
Copy link

whulixiya commented Jun 4, 2020 via email

@carlmalamud
Copy link

@wkentaro What is happening is your cookie keeps growing and growing until it is full. I believe every time there is a warning, a new line gets added. I've seen my cookie grow from 11 warnings to 36 warnings in about 2 hours. After about 1,000 files, there are presumably enough that there isn't room for more warnings, so you when present the cookie that doesn't mention a particular download, Google rejects it and your code is thinking that it is a permission issue.

Perhaps if your cookie fails, you could remove it, try again, and only then if it fails a second time assume it is a permissions issue.

Here is a snippet of what my cookie looks like:

[
[
"AUTH_22nmp4ombsvnvmjrl3nb3u3hsrucc95e",
"14651752893030988712Z|1591294950000|hospjjjbfh4rapv59tff247rc9fhcbr3"
],
[
"NID",
"204=x4h9LoiFMtrKRVT3aYaAXNxcePhv5SjsTw9qrioaMhrWD61BLoO_hbjosmcIBEYKSEf-pqz0U5D9SyUKwCiHJJ1Ys_xGBVg8oLqizpJaVYdWUoSIgSZKNL3xpkoGvIQs9lz8hTQD9EgvcwunJ--j5FtM7OPAn_W8mnVaHEVweSs"
],
[
"download_warning_13058876669334088843_0B7JhzNLs-FQEMExkMlBpOUJoQ28",
"IcVe"
],
[
"download_warning_13058876669334088843_0B7JhzNLs-FQEMmVDYVJUckNQZlE",
"Ricd"
],
[
"download_warning_13058876669334088843_0B7JhzNLs-FQENGlEZDNabFRwVzg",
"579P"
],
[
"download_warning_13058876669334088843_0B7JhzNLs-FQENk9JWmNMNm81R0k",
"o4Bf"
],
[
"download_warning_13058876669334088843_0B7JhzNLs-FQENlVqTnJsc2R5dzA",
"osl-"
],
[
"download_warning_13058876669334088843_0B7JhzNLs-FQEOGpkZzFad25SdFE",
"8XbE"
],

@carlmalamud
Copy link

It looks like the magic number is 110 download_warnings and the cookie is full.

@wkentaro
Copy link
Owner

wkentaro commented Jun 6, 2020

@carlmalamud thanks!

@wkentaro
Copy link
Owner

wkentaro commented Jun 6, 2020

Sent a PR here: #55

@wkentaro
Copy link
Owner

wkentaro commented Jun 6, 2020

Released as v3.11.1

@wkentaro
Copy link
Owner

wkentaro commented Jun 6, 2020

@carlmalamud can you try if the new version eases the issue?

@grudloff
Copy link

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

@carlmalamud
Copy link

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.

@carlmalamud
Copy link

I am imagining that the error might have something to do with my being an authenticated user in the browser and not via gdown. I'm not sure is presenting an oauth token might make a difference here?

@wkentaro
Copy link
Owner

I'm not sure is presenting an oauth token might make a difference here?

I don't think so, gdown uses requests inside without using any browsers.

@kshitijagrwl
Copy link

kshitijagrwl commented Jul 6, 2020

Solved by disabling certificate verification by changing line 111 in download.py

res = sess.get(url, stream=True, verify=False)

However it does display this warning
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning

@wkentaro
Copy link
Owner

wkentaro commented Jul 6, 2020

Solved by disabling certificate verification

In my case, it didn't work.

@aasyedd1
Copy link

@e96031413 worked like a charm. thanks alot

@neeeal
Copy link

neeeal commented Jan 17, 2024

pip install gdown==4.6.0

actually solved my issue. thanks

@wkentaro wkentaro unpinned this issue Jan 20, 2024
@wkentaro
Copy link
Owner

This PR #300 should help this issue in some regard. I also added FAQ to the README.
https://github.com/wkentaro/gdown?tab=readme-ov-file#i-set-the-permission-anyone-with-link-but-still-cant-download

Releasing v5.0.0 soon.

@pmeier
Copy link
Contributor

pmeier commented Jan 29, 2024

When hitting large files that GDrive wants extra confirmation before it starts the download, e.g. https://drive.google.com/uc?id=1r6o0pSROcV1_VwT4oSjA2FBUSCWGuxLK, we currently hit this branch:

gdown/gdown/download.py

Lines 31 to 35 in ae122f4

m = re.search('id="download-form" action="(.+?)"', line)
if m:
url = m.groups()[0]
url = url.replace("&", "&")
break

The relevant corresponding HTML looks like

<form id="download-form" action="https://drive.usercontent.google.com/download" method="get">
	<input type="submit" id="uc-download-link" class="goog-inline-block jfk-button jfk-button-action" value="Download anyway"/>
	<input type="hidden" name="id" value="1r6o0pSROcV1_VwT4oSjA2FBUSCWGuxLK">
	<input type="hidden" name="confirm" value="t">
	<input type="hidden" name="uuid" value="ce320bab-e9f0-4d0d-a9d8-8cede0161915">
</form>

The branch above just extracts https://drive.usercontent.google.com/download from it and this later fails other checks as this doesn't provide a file.

What we should do here is to extract the other parts of the form as well and append them as query. So for this example https://drive.usercontent.google.com/download?id=1r6o0pSROcV1_VwT4oSjA2FBUSCWGuxLK&confirm=t&uuid=ce320bab-e9f0-4d0d-a9d8-8cede0161915. As you can see this link also includes confirm=t that multiple people in this thread have already mentioned. I'll send a PR to fix this.

@pmeier
Copy link
Contributor

pmeier commented Jan 29, 2024

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

@wkentaro wkentaro reopened this Feb 1, 2024
@wkentaro
Copy link
Owner

wkentaro commented Feb 1, 2024

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.

@vanloc1808
Copy link

@wkentaro Hi, I observed that only downgrading to 4.6.0 helps, new version does not help :(

@wkentaro
Copy link
Owner

Can you please give me an example url?

@vanloc1808
Copy link

@vanloc1808
Copy link

vanloc1808 commented Feb 24, 2024

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

@wkentaro
Copy link
Owner

@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

@vanloc1808
Copy link

@wkentaro it works for me, thank you!

@Junyi42
Copy link

Junyi42 commented Mar 2, 2024

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.

Restarting the terminal after the downgrading works for me!

@AndrewLt
Copy link

AndrewLt commented Mar 7, 2024

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

@julienboussard
Copy link

julienboussard commented Mar 8, 2024

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

@ArianAmani
Copy link

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!

@ain-soph
Copy link

@wkentaro I'm still suffering this issue today. (gdown version 5.2.0)

I'm trying to download my own uploaded dataset (10G)
https://drive.google.com/uc?id=1vv73kAHiKb4KiL_oIH4DOWzUoaTeKzt_

And it raises the error

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


Failed to retrieve file url:

        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:

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

but Gdown can't. Please check connections and **permissions.**

@JiaHeng-DLUT 's workaround works for me (https://stackoverflow.com/questions/65312867/how-to-download-large-file-from-google-drive-from-terminal-gdown-doesnt-work)

@wkentaro
Copy link
Owner

wkentaro commented Jun 14, 2024

@ain-soph It works for me now, so looks like too many requests?

image

@JiaHeng-DLUT 's workaround works for me (https://stackoverflow.com/questions/65312867/how-to-download-large-file-from-google-drive-from-terminal-gdown-doesnt-work)

We can't do this because the scope of gdown is without logging in.

this is another workaround: https://github.com/wkentaro/gdown?tab=readme-ov-file#i-set-the-permission-anyone-with-link-but-i-still-cant-download

@cleanerspam
Copy link

#!/bin/bash

# Prompt for access token
read -p "Enter your Google Drive access token: " ACCESS_TOKEN

# Define the input file containing URLs
INPUT_FILE="file_urls.txt"

# Define the output directory
OUTPUT_DIR="/mnt/harddrive/gdrive"

# Check if the input file exists
if [[ ! -f "$INPUT_FILE" ]]; then
    echo "Input file '$INPUT_FILE' not found!"
    exit 1
fi

# Check if the output directory exists
if [[ ! -d "$OUTPUT_DIR" ]]; then
    echo "Output directory '$OUTPUT_DIR' does not exist!"
    exit 1
fi

# Loop through each line in the input file
while IFS= read -r URL; do
    # Extract the file ID from the URL
    FILE_ID=$(echo "$URL" | grep -oP 'd/\K[^/]+')

    # Check if FILE_ID was extracted successfully
    if [[ -z "$FILE_ID" ]]; then
        echo "Failed to extract file ID from URL: $URL"
        continue
    fi

    # Get the file metadata to retrieve the original name
    FILE_METADATA=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" "https://www.googleapis.com/drive/v3/files/$FILE_ID?fields=name")
    ORIGINAL_NAME=$(echo "$FILE_METADATA" | jq -r '.name')

    # Check if the original name was retrieved successfully
    if [[ -z "$ORIGINAL_NAME" ]]; then
        echo "Failed to retrieve original name for file ID: $FILE_ID"
        continue
    fi

    # Use curl to download the file to the specified output directory
    OUTPUT_FILE="$OUTPUT_DIR/$ORIGINAL_NAME"
    echo "Downloading file with ID: $FILE_ID as '$ORIGINAL_NAME' to '$OUTPUT_FILE'"
    curl -H "Authorization: Bearer $ACCESS_TOKEN" -C - "https://www.googleapis.com/drive/v3/files/$FILE_ID?alt=media" -o "$OUTPUT_FILE"

    # Check if the download was successful
    if [[ $? -eq 0 ]]; then
        echo "Downloaded: $OUTPUT_FILE"
    else
        echo "Failed to download file with ID: $FILE_ID"
    fi
done < "$INPUT_FILE"

To anybody reading this

  1. Install jq from your distro package manager
  2. Change the output_location in script to something of your liking
  3. Save the above code as download_drive_files.sh and
  4. enter all links of files in a text file named file_urls.txt in the same directory as the script
  5. Get AccessToken by following guide below
Going to OAuth 2.0 Playground https://developers.google.com/oauthplayground/
In the Select the Scope box, paste https://www.googleapis.com/auth/drive.readonly
Click Authorize APIs and then Exchange authorization code for tokens
Copy the Access token

This will save all the files that were mentioned in the file_urls.txt , just make there is only one url per line.

@secluls
Copy link

secluls commented Oct 14, 2024

@cleanerspam does the script works with gdrive folders?

@cleanerspam
Copy link

@cleanerspam does the script works with gdrive folders?

Try and tell , as far as I remember it was for individual links stored in a .txt file

@secluls
Copy link

secluls commented Oct 15, 2024

@cleanerspam I tried it out, but unfortunately it didn’t work. The script also didn’t work for some reason, as it only stores the files with no actual data inside. Still, a massive thank you for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug for issue
Projects
None yet