如何解决如何将 kaggle 数据集导入 PyCharm IDE
我可以使用 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,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."}'
解决方法
返回的错误描述了问题的根源:
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 网站并接受 那里的规则。
如果您接受了比赛,可能您没有使用与该用户对应的令牌进行身份验证。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。