Laurence Arbin
Laurence Arbin

Reputation: 51

azure.ai.translation.document in Python - Cannot access source document location with the current permissions

I've having problems with the azure.ai.translation.document library in Python. I have set up the translation service in Azure along with a blob storage with two containers. I've created my SAS connections using a 'User Delegation key'. One for source (Read / List) and one for target (Write / List).
e.g.
enter image description here

I tried running the Python program, but the file in the source blob was not translated an saved to the target blob.

I'm getting this error: azure.core.exceptions.HttpResponseError: (InvalidDocumentAccessLevel): Cannot access source document location with the current permissions.

I've using this example: https://learn.microsoft.com/en-us/azure/cognitive-services/translator/document-translation/client-sdks?tabs=python

import os from azure.core.credentials import AzureKeyCredential from azure.ai.translation.document import DocumentTranslationClient

key = "<your-key>" endpoint = "<your-custom-endpoint>" sourceUrl = "<your-container-sourceUrl>" targetUrl = "<your-container-targetUrl>"

client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))

poller = client.begin_translation(sourceUrl, targetUrl, "fr")
result = poller.result()

print("Status: {}".format(poller.status()))
print("Created on: {}".format(poller.details.created_on))
print("Last updated on: {}".format(poller.details.last_updated_on))
print("Total number of translations on documents: {}".format(poller.details.documents_total_count))

print("\nOf total documents...")
print("{} failed".format(poller.details.documents_failed_count))
print("{} succeeded".format(poller.details.documents_succeeded_count))

for document in result:
    print("Document ID: {}".format(document.id))
    print("Document status: {}".format(document.status))
    if document.status == "Succeeded":
        print("Source document location: {}".format(document.source_document_url))
        print("Translated document location: {}".format(document.translated_document_url))
        print("Translated to language: {}\n".format(document.translated_to))
    else:
        print("Error Code: {}, Message: {}\n".format(document.error.code, document.error.message))

I'm using Thonny in Windows in an Enterprise Environment (as I'm still trying to learn Python). It's possible our cloud proxy is screwing with things.

Thanks

Loz

Upvotes: 1

Views: 1028

Answers (3)

Madhav Kumar
Madhav Kumar

Reputation: 169

Go to the Source or Destination Container -> Shared access tokens

  1. Then Select the Permissions based on the storage and requirement

enter image description here

  1. Select the Allowed protocols

enter image description here

check other setting based on your requirement -> then after copy the Blob SAS URL after clicking the Generate SAS token and URL -> pest it into the sourceUrl and targetUrl

ref: https://learn.microsoft.com/en-gb/azure/ai-services/translator/document-translation/how-to-guides/create-sas-tokens?tabs=Containers

Upvotes: 0

tirexx
tirexx

Reputation: 29

Here you can find the solution for your problem: https://learn.microsoft.com/en-us/answers/questions/1286278/cannot-access-source-document-location-with-the-cu

Basically, you need to explicitly set storage_type to StorageInputType.FILE. Seems translator fails to determine storage_type correctly for SAS urls.

translation_input = DocumentTranslationInput(
    source_url=source_url,    
    storage_type=StorageInputType.FILE,
    targets=[TranslationTarget(target_url=target_url, language=target_language)],
)

poller = client.begin_translation(inputs=[translation_input])

Upvotes: 0

instead of selecting HTTPS, select HTTPS and HTTP option, it should work.

Upvotes: 0

Related Questions