简体   繁体   English

S3 - 使用 boto3 访问“文件夹”内的 object

[英]S3 - Access object inside “folder” using boto3

Dealing with S3 I know that we don't have such thing as a folder but I will call it that way to try exemplification my problem.处理 S3 我知道我们没有文件夹之类的东西,但我会这样称呼它来尝试举例说明我的问题。 The bucket name is "Exemple".存储桶名称为“示例”。 Inside the bucket we have "/folder1", inside folder1 we have "/folder2" and inside folder2 we have "/goalFile.csv".在存储桶中我们有“/folder1”,在folder1 中有“/folder2”,在folder2 中有“/goalFile.csv”。 I am sure that the problem is not in the access key or in the secret access key.我确信问题不在于访问密钥或秘密访问密钥。 Here it is what I have been trying:这是我一直在尝试的:

import sys
if sys.version_info[0] <3:
  from StringIO import StringIO #Python 2.X
else:
  from io import StringIO #Python 3.X

client = boto3.client('s3', aws_access_key_id='myKeyID',
                      aws_secret_access_key='mySecretKeyID')
    
bucket_name = 'exemple'
object_key ="/folder1/folder2/goalFile.csv" 

csv_obj = client.get_object(Bucket=bucket_name, Key=object_key)
body = csv_obj['Body']
csv_string= body.read().decode('utf-8')

i got the following error message: "ClientError: An error occurred (SignatureDoesNotMatch) when calling the GetObject operation: The request signature we calculated does not match the signature you provided. Check your key and signing method."我收到以下错误消息:“ClientError:调用 GetObject 操作时发生错误(SignatureDoesNotMatch):我们计算的请求签名与您提供的签名不匹配。请检查您的密钥和签名方法。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM