[英]Amazon Rekognition : AccessDeniedException , User is not authorized to perform: rekognition:DetectText
我正在尝试使用文本检测并运行示例代码以了解其工作原理。 我的代码如下:
以字节格式传递图像的代码给出错误:
botocore.errorfactory.AccessDeniedException: An error occurred (AccessDeniedException) when calling the DetectText operation: User is not authorized to perform: rekognition:DetectText because no identity-based policy allows the rekognition:DetectText action
代码是:
from PIL import Image
import io
local='Dauntless.jpg'
client = boto3.client('rekognition', region_name='region name here',aws_access_key_id="keyId here",aws_secret_access_key="key here")
image = Image.open(local)
stream = io.BytesIO()
image.save(stream,format="JPEG")
image_binary = stream.getvalue()
response = client.detect_text(Image={'Bytes':image_binary})
print(response)
我尝试了另一个代码如下,它也返回相同的错误。
import boto3
def detect_text(photo, bucket):
client=boto3.client('rekognition', region_name='name 'here ,aws_access_key_id="key here",aws_secret_access_key="key here")
response=client.detect_text(Image={'S3Object':{'Bucket':bucket,'Name':photo}})
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)
def main():
bucket='bucketname'
photo='Dauntlessss_52a311a2-884a-4bcb-ba29-d705c5a2ea12.jpg'
text_count=detect_text(photo,bucket)
print("Text detected: " + str(text_count))
if __name__ == "__main__":
main()
这两个代码都返回相同的错误。 关于我在这里缺少什么的任何帮助? 我是 AWS 的新手。
未应用适当的策略/许可。
请正确阅读 Amazon Rekognition 基于身份的政策。 以下示例授予对 Amazon Rekognition 资源的完全访问权限。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rekognition:*"
],
"Resource": "*"
}
]
}
aws教程链接https://docs.aws.amazon.com/rekognition/latest/dg/security_iam_id-based-policy-examples.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.