【问题标题】:Amazon Rekognition error when trying to access S3 file尝试访问 S3 文件时出现 Amazon Rekognition 错误
【发布时间】:2021-10-28 03:12:33
【问题描述】:

这是我在尝试对 s3 存储桶中的图像运行文本检测时看到的错误:botocore.errorfactory.InvalidS3ObjectException: An error occurred (InvalidS3ObjectException) when calling the DetectText operation: Unable to get object metadata from S3. Check object key, region and/or access permissions.

bucket -> 存储桶的名称 name -> 文件名(例如:123.jpg)

我的代码(python):

client=boto3.client('rekognition', region_name='us-east-1')
    print('works till here')
    response=client.detect_text(Image={'S3Object':{'Bucket': bucket,'Name': name}})
    print('works till here 2')
                        
    textDetections=response['TextDetections']
    print ('Detected text\n----------')
    for text in textDetections:
            print ('Detected text:' + text['DetectedText'])
            print ('Confidence: ' + "{:.2f}".format(text['Confidence']) + "%")
            print ('Id: {}'.format(text['Id']))
            if 'ParentId' in text:
                print ('Parent Id: {}'.format(text['ParentId']))
            print ('Type:' + text['Type'])
            print()
    return len(textDetections)

S3 bucket is on global and rekogntion is on us-east-1

【问题讨论】:

  • Amazon S3 存储桶是否也在us-east-1 中? (请注意,存储桶不是全局的——它们位于特定区域中。)尝试使用同一区域中的存储桶。
  • 嗨!是的,它也在 us-east-1 中

标签: python amazon-web-services amazon-s3 amazon-rekognition


【解决方案1】:

我获取了您的代码,修改它以引用我的存储桶和对象,然后导入 boto3。

它给出了与您收到的完全相同的相同的错误。然后我意识到我的存储桶在悉尼地区,所以我删除了region_name 参数,所以它将使用我的默认地区(悉尼)。

然后我再次运行它,效果很好

作为一个实验,我随后将Name 更改为指向一个不存在的对象。它再次给出了错误消息。

因此,您的问题很可能是存储桶在us-east-1,或者提供了不正确的存储桶名称或密钥。

【讨论】:

    猜你喜欢
    • 2014-02-03
    • 2019-10-11
    • 2016-03-30
    • 2016-04-19
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 2022-08-02
    • 2016-11-01
    相关资源
    最近更新 更多