Python can';t存储来自aws重新点火响应的数据

Python can';t存储来自aws重新点火响应的数据,python,amazon-web-services,metadata,boto3,amazon-rekognition,Python,Amazon Web Services,Metadata,Boto3,Amazon Rekognition,我需要存储和打印来自AWS rekognition的ResponseMetadata的响应数据,但我有一个错误。我用python编写代码 错误: File "example_eguest_search_V6.py", line 32, in <module> data = match['HTTPHeaders']['date'] TypeError: string indices must be integers, not str AWS Rekognion的响应: {

我需要存储和打印来自AWS rekognition的ResponseMetadata的响应数据,但我有一个错误。我用python编写代码

错误:

  File "example_eguest_search_V6.py", line 32, in <module>
  data = match['HTTPHeaders']['date']
  TypeError: string indices must be integers, not str
AWS Rekognion的响应:

{u'SearchedFaceBoundingBox':{u'Width':0.4403832256793976,u'Top':0.304189592998688,u'Left':0.229599817945957184,u'Height':0.337591022250365},u'SearchedFaceConfidence':99.9995422363281,u'FaceMatches':[{u'Face':{u'BoundingBox':{u'Width':0.2706860005855603,u'Top':0.2908029854297638,u'Left':0.3772050142288208,u'Height':0.3391779959201813},u'FaceId':u'965d9272-c16b-4055-ab3c-02e70d5a59af','Confidence':100.0,u'ImageId':u'7397f3a2-f38c-38f9-8f96-A059AA56635',,u'Similarity':u'84221914},u'facebox:{{u'Width':0.387249994087219,u'Top':0.32626101374626,u'Left':0.27909201385907,u'Height':0.408187000194358826},u'FaceId':u'384e2cdd-e0f5-4768-8365-aa01369b8394',u'Confidence':100.0,u'ImageId':u'c0239570-285b-3ac0-9614-be6f2ec872c1},u'Similarity':u'60191345844},u'Face':{{u'Width':0.38614898920059204,u'Top':0.40111250138282776,u'Left':0.502331972221924,u'Height':0.4669739902019501},u'FaceId':u'08F557F-bd57-48ee-bc3e-8ae6bd7dfd66','Confidence':99.9999008178711,u'ImageId':u'996a26ce-d9dc-3f9d-bb0d-d61b78ad4422','u'Similarity'8694.2291481','FaceTadu'{'RetryAttempts':0,'HTTPStatusCode':200,'RequestId':'b0b35916-9db9-45db-810d-45b19153d4de','HTTPHeaders':{'date':'Sun,2019年10月27日14:36:14 GMT','x-amzn-RequestId':'b0b35916-9db9-45db-810d-45b19153d4de','content length','1071','content type':'application/x-amz-json-1.1','connection','keep alive'}}

细节可能是魔鬼:

CollectionId='test\u colaction'

集合中应包含“e”:

CollectionId='test\u collection'

其余部分请参见您尝试镜像的示例:

#文件:test-5-search-faces.py
进口boto3
BUCKET=“亚马逊重新认识”
KEY=“search.jpg”
COLLECTION=“我的收藏id”
按图像定义搜索面(桶、键、集合id、阈值=80,region=“eu-west-1”):
rekognition=boto3.客户(“rekognition”,地区)
response=rekognition.search_faces_by_image(
形象={
“S3Object”:{
“桶”:桶,
“名称”:键,
}
},
CollectionId=集合\u id,
FaceMatchThreshold=阈值,
)
返回响应['FaceMatches']
对于按图像搜索面中的记录(桶、键、集合):
面=记录['face']
打印“匹配的面({}%)”。格式(记录['Similarity'])
打印“FaceId:{}”。格式(face['FaceId'])
打印“ImageId:{}”。格式(面['ExternalImageId'])

发布的代码可以在github上找到。它的作者是用户alexcasalboni。

我创建的rekognition集合的名称是test\u colaction not test\u collection我们称之为“typo”。请参阅我发布的其他代码。尝试使用defs来保持监督,并在以后的另一种方法中启用它。“TypeError:字符串索引必须是整数,而不是str”这就是您的错误,使用整数而不是字符串来进行反索引,例如data=match[1][1]
 import boto3

 import io
 from PIL import Image

 rekognition = boto3.client('rekognition', region_name='eu-west-1')
 dynamodb = boto3.client('dynamodb', region_name='eu-west-1')

 image = Image.open("sample.jpeg")
 stream = io.BytesIO()
 image.save(stream,format="JPEG")
 image_binary = stream.getvalue()


 response = rekognition.search_faces_by_image(
    CollectionId='test_Colction',
    Image={'Bytes':image_binary}
    )
 print(response)


 for match in response['ResponseMetadata']:
     data = match['HTTPHeaders']['date']

    print(data)