【问题标题】:NoSuchKey error when using S3 .putobject on IBM Cloud Storage在 IBM Cloud Storage 上使用 S3 .putobject 时出现 NoSuchKey 错误
【发布时间】:2019-06-23 03:45:06
【问题描述】:

我正在学习 IBM 课程 Python for Data Science,在其中一个模块上,我不断收到一条错误消息。我按照说明使用 s3 和 putobject 将文件保存到 IBM 云对象存储上的存储桶中。它给了我一个 NoSuchKey 错误,但密钥被定义得更高

bucket_name = 'm4week5' 
html_path = '/home/dsxuser/work/index.html'
f = open(html_path,'r')
# Fill up the parameters in the following function:
# resource.Bucket(name=).put_object(Key=, Body=)
resource.Bucket(name = bucket_name).put_object(Key = html_path, Body = f.read())

错误信息:


NoSuchKey                                 Traceback (most recent call last)
<ipython-input-22-a728805063e5> in <module>()
      1 # Fill up the parameters in the following function:
      2 # resource.Bucket(name=).put_object(Key=, Body=)
----> 3 resource.Bucket(name = bucket_name).put_object(Key = html_path, Body = f.read())

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

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/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/botocore/client.py in _api_call(self, *args, **kwargs)
    310                     "%s() only accepts keyword arguments." % py_operation_name)
    311             # The "self" in this scope is referring to the BaseClient.
--> 312             return self._make_api_call(operation_name, kwargs)
    313 
    314         _api_call.__name__ = str(py_operation_name)

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
    599             error_code = parsed_response.get("Error", {}).get("Code")
    600             error_class = self.exceptions.from_code(error_code)
--> 601             raise error_class(parsed_response, operation_name)
    602         else:
    603             return parsed_response

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

【问题讨论】:

  • 请复制错误全文,帮助会员理解问题,更有机会得到解决方案。
  • 编辑现在包含错误信息,感谢您的建议

标签: python ibm-watson


【解决方案1】:

您收到此错误是因为您有不同的云存储端点

IBM Watson 工作室中的转到存储桶 选择存储桶端点选项复制公共端点 URL 并将其替换在笔记本的端点变量中,确保 https:// 存在。

同时更改 Key 参数 文件名 = 'index.html' 键 = 文件名

【讨论】:

    【解决方案2】:

    你可以很容易地看到 Python 解释器抛出的错误:

    NoSuchKey:调用 PutObject 时发生错误(NoSuchKey) 操作:指定的键不存在。

    您收到此错误是因为 putObject 无法找到指定的键,即 html_path。参数“key”应该是 HTML 文件的名称,即“index.html”。 所以你的电话应该是这样的:

    resource.Bucket(name=bucket_name).put_object(Key='index.html', Body=f.read())
    

    还要确保以下几点:

    • 端点名称应该以https:// 开头并且应该是一个字符串。您可以从 IBM Watson Studio 中 Buckets Configuration 页面上的任何可用公共端点中进行选择。
    • 如果您收到Access Denied 错误。确保您已为存储桶创建了 access policy

    【讨论】:

      猜你喜欢
      • 2019-10-14
      • 2013-03-22
      • 2014-02-28
      • 2020-04-10
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多