【问题标题】:How to import kaggle datasets to PyCharm IDE如何将 kaggle 数据集导入 PyCharm IDE
【发布时间】:2021-09-15 18:31:06
【问题描述】:

我可以使用 PIP 命令下载 kaggle。能够将 kaggle.json 文件放入相应的文件夹中。能够看到其中的比赛。但是当我尝试下载数据文件时,会显示一个错误。

代码:

import kaggle
from kaggle.api.kaggle_api_extended import KaggleApi
api = KaggleApi()
api.authenticate()
lis1 = api.competitions_list(search='LANL-Earthquake-Prediction')
api.competition_download_files('LANL-Earthquake-Prediction')

错误信息: 收到以下错误消息。

Traceback (most recent call last):
  File "C:\Users\rpremala003\PycharmProjects\MachineLearning\Importing datasets\Importing Kaggle through API.py", line 11, in <module>
    api.competition_download_files('LANL-Earthquake-Prediction')
  File "C:\Users\rpremala003\PycharmProjects\MachineLearning\venv\lib\site-packages\kaggle\api\kaggle_api_extended.py", line 718, in competition_download_files
    self.competitions_data_download_files_with_http_info(
  File "C:\Users\rpremala003\PycharmProjects\MachineLearning\venv\lib\site-packages\kaggle\api\kaggle_api.py", line 400, in competitions_data_download_files_with_http_info
    return self.api_client.call_api(
  File "C:\Users\rpremala003\PycharmProjects\MachineLearning\venv\lib\site-packages\kaggle\api_client.py", line 329, in call_api
    return self.__call_api(resource_path, method,
  File "C:\Users\rpremala003\PycharmProjects\MachineLearning\venv\lib\site-packages\kaggle\api_client.py", line 161, in __call_api
    response_data = self.request(
  File "C:\Users\rpremala003\PycharmProjects\MachineLearning\venv\lib\site-packages\kaggle\api_client.py", line 351, in request
    return self.rest_client.GET(url,
  File "C:\Users\rpremala003\PycharmProjects\MachineLearning\venv\lib\site-packages\kaggle\rest.py", line 247, in GET
    return self.request("GET", url,
  File "C:\Users\rpremala003\PycharmProjects\MachineLearning\venv\lib\site-packages\kaggle\rest.py", line 241, in request
    raise ApiException(http_resp=r)
kaggle.rest.ApiException: (403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({'Date': 'Sun, 04 Jul 2021 19:34:22 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'ka_sessionid=232614eb67b588938ac922774220f567; max-age=2626560; path=/, GCLB=CPDc0e-esJK-ZQ; path=/; HttpOnly', 'Vary': 'Accept-Encoding', 'Access-Control-Allow-Credentials': 'true', 'Turbolinks-Location': 'https://www.kaggle.com/api/v1/competitions/data/download-all/LANL-Earthquake-Prediction', 'X-Kaggle-MillisecondsElapsed': '91', 'X-Kaggle-RequestId': 'd485fdb0e4674834b5c1b444fd9885de', '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-q8ly/A24jHgL5gZmidMI6A==' 'report-sample' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:; 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-production.firebaseapp.com https://apis.google.com https://content-sheets.googleapis.com/ https://accounts.google.com/ https://storage.googleapis.com https://docs.google.com; base-uri 'none'; report-uri https://csp.withgoogle.com/csp/kaggle/20201130;", 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'Via': '1.1 google', 'Alt-Svc': 'clear'})
HTTP response body: b'{"code":403,"message":"You must accept this competition\\u0027s rules before you\\u0027ll be able to download files."}'

【问题讨论】:

    标签: pycharm artificial-intelligence kaggle


    【解决方案1】:

    返回的错误描述了问题的根源:

    HTTP response body: b'{"code":403,"message":"You must accept this competition\\u0027s rules before you\\u0027ll be able to download files."}'
    

    来自Kaggle API的文档:

    就像通过用户正常参加比赛一样 界面,您必须阅读并接受规则才能下载 数据或提交。 您不能通过接受竞赛规则 API。您必须通过访问 Kaggle 网站并接受 那里有规则。

    如果您接受了比赛,可能您没有使用与该用户对应的令牌进行身份验证。

    【讨论】:

    • 谢谢@drglove。
    猜你喜欢
    • 2019-10-29
    • 2018-08-28
    • 2019-07-18
    • 2019-01-28
    • 2021-10-24
    • 2022-01-25
    • 2016-11-21
    • 2020-04-28
    • 1970-01-01
    相关资源
    最近更新 更多