botocore.errorfactory.InvalidS3ObjectException:

botocore.errorfactory.InvalidS3ObjectException:

我正在尝试使用 python 代码通过 AWS 系统 运行 多个图像,这只是一个基本的 for 循环。当我 运行 代码时出现错误。我可以 运行 一张图片,但是一旦我尝试 运行 多张图片,我再次收到错误代码。

import boto3

if __name__ == "__main__":

bucket='fastlane'
photo=','.join(('test.png',
'test2.png',
'test3.png',
'test4.png',
'test5.png',
'test6.png',
'test7.png',
'test8.png',
'test9.png',
'test10.png',
'test11.png',
'test12.png',
'test13.png',
'test14.png',
'test15.png',
'test16.png',
'test17.png',
'test18.png'))




client=boto3.client('rekognition')


response=client.detect_text(Image={'S3Object': 
{'Bucket':bucket,'Name':photo}})


textDetections=response['TextDetections']
print (response)
print ('Matching faces')
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

错误代码: 追溯(最近一次通话): 文件 "main.py",第 37 行,位于 响应=client.detect_text(图像={'S3Object':{'Bucket':桶,'Name':照片}}) 文件“/home/Zeus/farcry/AWS/env/lib/python3.5/site-packages/botocore/client.py”,第 320 行,在 _api_call 中 return self._make_api_call(operation_name, kwargs) 文件“/home/Zeus/farcry/AWS/env/lib/python3.5/site-packages/botocore/client.py”,第 624 行,在 _make_api_call 中 提高 error_class(parsed_response, operation_name) botocore.errorfactory.InvalidS3ObjectException:调用 DetectText 操作时发生错误 (InvalidS3ObjectException):无法从 S3 获取对象元数据。检查对象键、区域 and/or 访问权限。

您将所有名称连接成一个大字符串并将其作为对象的名称传递,除非您的 s3 对象被调用 test1.png,test2.png, etc.

来自文档:

Name (string) -- S3 object key name

您必须为每张照片调用 detect_text。

您可以做的是:

import boto3

if __name__ == "__main__":

    bucket='fastlane'
    client=boto3.client('rekognition')
    photos= ['test.png',
    'test2.png',
    'test3.png',
    'test4.png',
    'test5.png',
    'test6.png',
    'test7.png',
    'test8.png',
    'test9.png',
    'test10.png',
    'test11.png',
    'test12.png',
    'test13.png',
    'test14.png',
    'test15.png',
    'test16.png',
    'test17.png',
    'test18.png']

    for photo in photos:
        response=client.detect_text(Image={'S3Object':
        {'Bucket':bucket,'Name':photo}})

        textDetections=response['TextDetections']
        print (response)
        print ('Matching faces')
        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'])