Skip to content

Textract via API

0

Hi. I am new with AWS services and I am trying to use Textract via python. I made the download of following python script from AWS template: import boto3 from trp import Document

Document

documentName = R'E:\fotos\aaa.jpg' print (documentName)

boto3.setup_default_session(profile_name='default')

secretsmanager = boto3.client('secretsmanager')

Amazon Textract client

textract = boto3.client('textract')

Call Amazon Textract

with open(documentName, "rb") as document: response = textract.analyze_document( Document={ 'Bytes': document.read(), }, FeatureTypes=["TABLES"])

#print(response)

doc = Document(response)

for page in doc.pages: # Print tables for table in page.tables: for r, row in enumerate(table.rows): for c, cell in enumerate(row.cells): print("Table[{}][{}] = {}".format(r, c, cell.text))

I created a lot of king of users: portal and IAM user, with or without MFA nor Alias. Of course all of them using AWS configure to create a credentials file (evey time delete the file first). When I run the script, every time i got: when calling the AnalyzeDocument operation: The security token included in the request is invalid.

Finally I decide to create a simple user with id and password without IAM nor MFA for this user. Run again aws configure with input for Access Key ID e Secret Access Key. The remains parameters I assumed the default: region=us-east-1 e output=json.

As this user does not have MFA, i did not run aws sts. Even thought I got the error of invalid token. Can anybody help me on this. I am trying for a month to test Textract and I am in a authorization phase yet. Very frustrating.

asked a year ago216 views
1 Answer
0

It sounds like the identity information in your AWS profile is not correct.

Please do not post your AWS configuration files here; but what you should have in your ~/.aws/credentials file is something like:

[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Note that you don't need boto3.setup_default_session(profile_name='default') because the default profile is "default" already.

If you're using IAM user credentials, delete them and create a new set of credentials then paste them into the credentials file.

AWS
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.