Kaggle / kaggle-api

Official Kaggle API
Apache License 2.0
6.12k stars 1.08k forks source link

403 - "Required permission \\u0027competitions.get\\u0027 was not satisfied" #448

Closed rusmux closed 1 year ago

rusmux commented 1 year ago

I'm trying to download a file (https://www.kaggle.com/competitions/planet-understanding-the-amazon-from-space/data?select=train-jpg) from a competition via Kaggle Python API. I have verified my phone number and agreed to the rules. I can download this file by clicking download button on the competition page, however I cannot achieve the same behavior using the Python API.

There is my code:

import os
from kaggle.api.kaggle_api_extended import KaggleApi

os.environ['KAGGLE_USERNAME'] = "..."
os.environ['KAGGLE_KEY'] = "..."

api = KaggleApi()
api.authenticate()

api.competition_download_file(
    "https://www.kaggle.com/competitions/planet-understanding-the-amazon-from-space",
    file_name="train-jpg.tar",
)

Which gives me the following error:

ApiException: (403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Date': 'Fri, 11 Nov 2022 13:48:05 GMT', 'Access-Control-Allow-Credentials': 'true', 'Set-Cookie': 'ka_sessionid=784943a92e161bfa180fab993ddcc666; max-age=2626560; path=/, GCLB=CKDNqO3avrbqsQE; path=/; HttpOnly', 'Transfer-Encoding': 'chunked', 'Vary': 'Accept-Encoding', 'Turbolinks-Location': 'https://www.kaggle.com/api/v1/competitions/data/download/https:%2F%2Fwww.kaggle.com%2Fcompetitions%2Fplanet-understanding-the-amazon-from-space/train-jpg.tar', 'X-Kaggle-MillisecondsElapsed': '55', 'X-Kaggle-RequestId': 'f084d8e53713571bbc0444a72e2668aa', 'X-Kaggle-ApiVersion': '1.5.12', 'X-Frame-Options': 'SAMEORIGIN', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload', 'Content-Security-Policy': "object-src 'none'; script-src 'nonce-iixVT2sntrpXQofWC8rjIw==' 'report-sample' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: [http:;](http://localhost:8888/notebooks/;) frame-src 'self' https://www.kaggleusercontent.com/ https://www.youtube.com/embed/ https://polygraph-cool.github.io/ https://www.google.com/recaptcha/ https://form.jotform.com/ https://submit.jotform.us/ https://submit.jotformpro.com/ https://submit.jotform.com/ https://www.docdroid.com/ https://www.docdroid.net/ https://kaggle-static.storage.googleapis.com/ https://kaggle-static-staging.storage.googleapis.com/ https://kkb-dev.jupyter-proxy.kaggle.net/ https://kkb-staging.jupyter-proxy.kaggle.net/ https://kkb-production.jupyter-proxy.kaggle.net/ https://kkb-dev.firebaseapp.com/ https://kkb-staging.firebaseapp.com/ https://kkb-production.firebaseapp.com/ https://kaggle-metastore-test.firebaseapp.com/ https://kaggle-metastore.firebaseapp.com/ https://apis.google.com/ https://content-sheets.googleapis.com/ https://accounts.google.com/ https://storage.googleapis.com/ https://docs.google.com/ https://drive.google.com/ https://calendar.google.com/; base-uri 'none'; report-uri [https://csp.withgoogle.com/csp/kaggle/20201130;",](https://csp.withgoogle.com/csp/kaggle/20201130;%22,) 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'Via': '1.1 google', 'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'})
HTTP response body: b'{"code":403,"message":"Required permission \\u0027competitions.get\\u0027 was not satisfied"}'

I'm using Kaggle version 1.5.12.

ucas010 commented 1 year ago

have the similar problem, can't download kaggle competitions download avazu-ctr-prediction just tell me 403 - Forbidden

rusmux commented 1 year ago

@ucas010 You have the same issue with the Kaggle cli? You can get 403 - Forbidden if you didn't accept the rules of the competition. I tried and I can download it with kaggle competitions download avazu-ctr-prediction after accepting the rules.

Philmod commented 1 year ago

https://github.com/Kaggle/kaggle-api/releases/tag/1.5.14