将数据集加载到存储桶中我做错了什么?

What am I doing wrong loading my dataset into a bucket?

我是 Python 的新手,并且在 Python 中参加了在线介绍 Python 的数据科学课程。我有一项任务要完成,这看起来很容易,而且进展顺利,直到接近尾声。

不得不通过网络抓取四名球员的篮球统计数据,为每个球员创建字典和数据框,最后保存,创建一个 URL 来分享,并与教练分享那个 URL。

我已经走到这一步了:

要将数据集加载到存储桶中,我们将使用方法 put_object,您必须将参数名称设置为存储桶的名称,参数 Key 应为 csv 文件的名称文件和参数 Body 的值应设置为 f.read().

我已经更改了文件名,玩了几个小时,仍然出现各种错误。在修复之前,我无法保存任何内容以供分享。我在 Watson Studio 工作。那就是我设置存储桶的地方。那就是需要放置对象的地方。 class 让我们在 Jupyter notebook 中工作。

resource.Bucket(name='cahill-pythonbasics-finalassignment').put_object(Key='lebron_james.csv', Body=f.read())

我需要将对象放入我创建的名为 "cahill-pythonbasics-finalassignment," 的存储桶中,但我却收到错误消息。最近的是:

---------------------------------------------------------------------------
NoSuchKey                                 Traceback (most recent call last)
<ipython-input-391-bcdc2e3a317a> in <module>()
----> 1 resource.Bucket(name='cahill-pythonbasics-finalassignment').put_object(Key='lebron_james.csv', Body=f.read())

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/ibm_boto3/resources/factory.py in do_action(self, *args, **kwargs)
    515             # instance via ``self``.
    516             def do_action(self, *args, **kwargs):
--> 517                 response = action(self, *args, **kwargs)
    518 
    519                 if hasattr(self, 'load'):

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/ibm_boto3/resources/action.py in __call__(self, parent, *args, **kwargs)
     81                     operation_name, params)
     82 
---> 83         response = getattr(parent.meta.client, operation_name)(**params)
     84 
     85         logger.debug('Response: %r', response)

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/ibm_botocore/client.py in _api_call(self, *args, **kwargs)
    251                     "%s() only accepts keyword arguments." % py_operation_name)
    252             # The "self" in this scope is referring to the BaseClient.
--> 253             return self._make_api_call(operation_name, kwargs)
    254 
    255         _api_call.__name__ = str(py_operation_name)

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/ibm_botocore/client.py in _make_api_call(self, operation_name, api_params)
    541             error_code = parsed_response.get("Error", {}).get("Code")
    542             error_class = self.exceptions.from_code(error_code)
--> 543             raise error_class(parsed_response, operation_name)
    544         else:
    545             return parsed_response

NoSuchKey: An error occurred (NoSuchKey) when calling the PutObject operation: The specified key does not exist.

我正在上同样的 Coursera 课程。我认为他们拼错了 "csv"。是 html。 因此,而不是“[...] 参数 Key 应该是 csv 文件的名称 [...]” 他们的意思是 html.

尝试重新创建您的存储桶。我 运行 一开始遇到这个错误,但是在 us-geo 中创建一个新的跨区域存储桶解决了这个问题