【Azure】AI Document Intelligenceで400 | 夕湖津のブログ

夕湖津のブログ

問題解決に役立つ情報の提供を目指します

■事象

url = "ここに解析対象URL"

client = ここにクライアント定義コード

 

poller = client.begin_analyze_document_from_url(
            model_id = "prebuilt-read",
            document_url = url,
     )

 

上記コード実行で下記エラー(どんなURLでもそうなる場合は、当記事が参考になるはずです)

 

 (InvalidRequest) Invalid request.
 Code: InvalidRequest
 Message: Invalid request.
 Inner error: {
     "code": "InvalidContent",
     "message": "The file is corrupted or format is unsupported. Refer to documentation for the list of supported formats."
}

 

■原因(の一つ)

azure-ai-document-intelligenceのバージョンが3.3未満の可能性あり

 

■対応

$ pip show azure-ai-formrecognizer

で現在のバージョンを確認し、3.2以下でしたら、下記で最新にして下さい。

 

$ pip install -U azure-ai-formrecognizer

:

:

$ pip show azure-ai-formrecognizer
Name: azure-ai-formrecognizer
Version: 3.3.2
Summary: Microsoft Azure Form Recognizer Client Library for Python
Home-page: https://github.com/Azure/azure-sdk-for-python
Author: Microsoft Corporation
Author-email: azpysdkhelp@microsoft.com
License: MIT License
Location: /home/hoge/miniconda3/lib/python3.11/site-packages
Requires: azure-common, azure-core, msrest, typing-extensions
Required-by: 

 

これでうまくいくはずです。

再度400エラーになったら、clientの設定(endpointやcredentialミスなど)を次に疑って下さい。