0

Python用のboto3を使用してaws texttractを実装している間。

コード:

import boto3

# Document
documentName = "/home/niranjan/IdeaProjects/amazon-forecast-samples/notebooks/basic/Tutorial/cert.pdf"

# Read document content
with open(documentName, 'rb') as document:
    imageBytes = bytearray(document.read())

print(type(imageBytes))

# Amazon Textract client
textract = boto3.client('textract', region_name='us-west-2')

# Call Amazon Textract
response = textract.detect_document_text(Document={'Bytes': imageBytes})

以下は、awsの資格情報と構成ファイルです

niranjan@niranjan:~$ cat ~/.aws/credentials
[default]
aws_access_key_id=my_access_key_id
aws_secret_access_key=my_secret_access_key

niranjan@niranjan:~$ cat ~/.aws/config 
[default]
region=eu-west-1

この例外が発生しています:

---------------------------------------------------------------------------
UnsupportedDocumentException              Traceback (most recent call last)
<ipython-input-11-f52c10e3f3db> in <module>
     14 
     15 # Call Amazon Textract
---> 16 response = textract.detect_document_text(Document={'Bytes': imageBytes})
     17 
     18 #print(response)

~/venv/lib/python3.7/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
    314                     "%s() only accepts keyword arguments." % py_operation_name)
    315             # The "self" in this scope is referring to the BaseClient.
--> 316             return self._make_api_call(operation_name, kwargs)
    317 
    318         _api_call.__name__ = str(py_operation_name)

~/venv/lib/python3.7/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
    624             error_code = parsed_response.get("Error", {}).get("Code")
    625             error_class = self.exceptions.from_code(error_code)
--> 626             raise error_class(parsed_response, operation_name)
    627         else:
    628             return parsed_response

UnsupportedDocumentException: An error occurred (UnsupportedDocumentException) when calling the DetectDocumentText operation: Request has unsupported document format

私は AWS のテキストに少し慣れていません。どんな助けでも大歓迎です。

4

2 に答える 2