gpt4 book ai didi

python - Kaggle 数据集到 jupyter notebook

转载 作者:太空宇宙 更新时间:2023-11-03 14:41:44 24 4
gpt4 key购买 nike

我正在尝试将一些数据从 kaggle 导入到笔记本中。我收到的错误是 401 unauthorized,但是我已经接受了比赛规则并且可以下载数据。

这是我正在运行的代码:

from kaggle.api.kaggle_api_extended import KaggleApi

api = KaggleApi()
files = api.competition_download_files("twosigmanews")
api.competitions_submit("submission.csv", "my submission message", "twosigmanews")

编辑:添加了更多错误:无论我希望导入哪个 kaggle 数据,我都会得到相同的错误。


ApiException                              Traceback (most recent call last)
<ipython-input-7-65a92f19da82> in <module>()
2
3 api = KaggleApi()
----> 4 files = api.competition_download_files("twosigmanews")
5 api.competitions_submit("submission.csv", "my submission message", "twosigmanews")

~\Anaconda3\lib\site-packages\kaggle\api\kaggle_api_extended.py in competition_download_files(self, competition, path, force, quiet)
637 quiet: suppress verbose output (default is False)
638 """
--> 639 files = self.competition_list_files(competition)
640 if not files:
641 print('This competition does not have any available data files')

~\Anaconda3\lib\site-packages\kaggle\api\kaggle_api_extended.py in competition_list_files(self, competition)
554 """
555 competition_list_files_result = self.process_response(
--> 556 self.competitions_data_list_files_with_http_info(id=competition))
557 return [File(f) for f in competition_list_files_result]
558

~\Anaconda3\lib\site-packages\kaggle\api\kaggle_api.py in competitions_data_list_files_with_http_info(self, id, **kwargs)
416 _preload_content=params.get('_preload_content', True),
417 _request_timeout=params.get('_request_timeout'),
--> 418 collection_formats=collection_formats)
419
420 def competitions_list(self, **kwargs): # noqa: E501

~\Anaconda3\lib\site-packages\kaggle\api_client.py in call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, async_req, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
332 response_type, auth_settings,
333 _return_http_data_only, collection_formats,
--> 334 _preload_content, _request_timeout)
335 else:
336 thread = self.pool.apply_async(self.__call_api, (resource_path,

~\Anaconda3\lib\site-packages\kaggle\api_client.py in __call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
163 post_params=post_params, body=body,
164 _preload_content=_preload_content,
--> 165 _request_timeout=_request_timeout)
166
167 self.last_response = response_data

~\Anaconda3\lib\site-packages\kaggle\api_client.py in request(self, method, url, query_params, headers, post_params, body, _preload_content, _request_timeout)
353 _preload_content=_preload_content,
354 _request_timeout=_request_timeout,
--> 355 headers=headers)
356 elif method == "HEAD":
357 return self.rest_client.HEAD(url,

~\Anaconda3\lib\site-packages\kaggle\rest.py in GET(self, url, headers, query_params, _preload_content, _request_timeout)
249 _preload_content=_preload_content,
250 _request_timeout=_request_timeout,
--> 251 query_params=query_params)
252
253 def HEAD(self, url, headers=None, query_params=None, _preload_content=True,

~\Anaconda3\lib\site-packages\kaggle\rest.py in request(self, method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)
239
240 if not 200 <= r.status <= 299:
--> 241 raise ApiException(http_resp=r)
242
243 return r

ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Cache-Control': 'private', 'Content-Length': '37', 'Content-Type': 'application/json; charset=utf-8', 'X-MiniProfiler-Ids': '["b1df1310-4d5b-4000-8f43-e5b6f4958a48","b9dcdaa4-64ef-4be1-bbbe-90fe664a81bd","db1868eb-0a12-4217-a89a-5cbb3946b0e7","b8166dda-a74f-4e64-8bd4-fe529e95bf04","205f9250-b5eb-4cfd-b94c-976778be8f17","229360b9-37d4-456f-b030-9e56879d7c84"]', 'X-Frame-Options': 'SAMEORIGIN', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'Set-Cookie': 'ARRAffinity=87506ffb959c51b2ba135ec75a7dffc3bc28e2948e5cb4ee012d8d916b147438;Path=/;HttpOnly;Domain=www.kaggle.com', 'Date': 'Sat, 06 Oct 2018 16:23:01 GMT'})
HTTP response body: {"code":401,"message":"Unauthorized"}

最佳答案

我认为比赛的名称是错误的。尝试:

from kaggle.api.kaggle_api_extended import KaggleApi

api = KaggleApi('copy and paste kaggle.json content here')
api.authenticate()
files = api.competition_download_files("two-sigma-financial-news")

关于python - Kaggle 数据集到 jupyter notebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52681196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com