question

KachaAno-4370 avatar image
0 Votes"
KachaAno-4370 asked TuanNguyen-0830 commented

Quick start for Document Translator returns 404 error

Hello,

I tried to run the document translator with the quick start following these instructions https://docs.microsoft.com/de-de/azure/cognitive-services/translator/document-translation/get-started-with-document-translation?tabs=python .
This however did not work. Running the code in post_document_request.py returned this:
response status code: 404
response status: Not Found
response headers: {'Content-Type': 'text/html', 'Server': 'Microsoft-IIS/10.0', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'Date': 'Sun, 07 Mar 2021 13:25:53 GMT', 'Content-Length': '1245'}
exept for the json code I used the provided python code.

Thank you for your help
k

azure-translator
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KachaAno-4370 I am curious to check if you have been granted access to this preview feature based on the error seen? It generally takes 2 business days to get access to the resource, once required access is provided you should be able to run the steps successfully. Thanks!!

0 Votes 0 ·
KachaAno-4370 avatar image
0 Votes"
KachaAno-4370 answered romungi-MSFT commented

I have preview access.

I'm a little unsure which I should put for the endpoint.
The mistake occoured when I used the endpoint under the rider "keys and endpoint": https://api.cognitive.microsofttranslator.com/

I also tried with this https://<NAME-OF-YOUR-RESOURCE>.cognitiveservices.azure.com/translator/text/batch/v1.0-preview.1
in that case I recive the following error:
response status code: 403
response status: Forbidden
response headers: {'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json', 'X-RequestId': '800027[...]67bb', 'Set-Cookie': 'ARRAffinity=5dd610bb[...]7d2a5eff0940e;Path=/;HttpOnly;Secure;Domain=doctrans.westus.microsofttranslator.com, ARRAffinitySameSite=5dd610bbbfcdcce1e8b7e0[...]536e67d2a5eff0940e;Path=/;HttpOnly;SameSite=None;Secure;Domain=doctrans.westus.microsofttranslator.com', 'X-Powered-By': 'ASP.NET', 'apim-request-id': '88920c4b[...]b332f91127ea', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'x-content-type-options': 'nosniff', 'Date': 'Mon, 08 Mar 2021 12:50:24 GMT'}

· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KachaAno-4370 You are using the correct endpoint according to your second request. Is your blob container given correct access to read/list the document and is the translator resource created with region as global?

0 Votes 0 ·

Thank you for your answer

Which one is the correct endpoint?
1. https://api.cognitive.microsofttranslator.com/ or
2. https://<NAME-OF-YOUR-RESOURCE>.cognitiveservices.azure.com/translator/text/batch/v1.0-preview.1

I checked again for the access they are all as they should be.



0 Votes 0 ·

The second path endpoint should work with path appended.

 https://<NAME-OF-YOUR-RESOURCE>.cognitiveservices.azure.com/translator/text/batch/v1.0-preview.1/batches
1 Vote 1 ·
Show more comments

@romungi-MSFT
Here is the code I used
I specified everything in all caps to my resources and nothing else
I called it with python filename.py

import requests

endpoint = "https://<NAME-OF-MY-RESOURCE>.cognitiveservices.azure.com/translator/text/batch/v1.0-preview.1"
subscriptionKey = '<MY-SUBSCRIPTION-KEY>'
path = '/batches'
constructed_url = endpoint + path

payload= {
"inputs": [
{
"source": {
"sourceUrl": "https://BLOB-SAS-URL-SORCE-WITH-READ-LIST-ACCESS-SAS",
"storageSource": "AzureBlob",
"language": "en",
"filter":{
"prefix": "Demo_1/" """need to change this? To what?"""
}
},
"targets": [
{
"targetUrl": "https://BLOB-SAS-URL-TARGET-WITH-WRITE-LIST-ACCESS-SAS",
"storageSource": "AzureBlob",
"category": "general",
"language": "es"
}
]
}
]
}
headers = {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-Type': 'application/json'
}

0 Votes 0 ·

Based on the above it looks like you are using the same prefix as the documentation. This is basically the folder in your container or a blob or a file that you need the API to pickup for translation. For example, in a container for which you provided list and read access upload a file called document.txt and use the following as prefix and suffix:

 "filter":{
 "prefix": "document",
 "suffix": ".txt"
 }

The SAS token or URL in this case is the SAS URL for the file instead of the container. The guidance in this page should help you choose the correct URL for a single file or a bunch of files along with the prefix and suffix that needs to be updated in the request.




0 Votes 0 ·
TuanNguyen-0830 avatar image
0 Votes"
TuanNguyen-0830 answered TuanNguyen-0830 commented

I have the same error: 404 - Forbidden. Here's the error description:

response status code: 403
response status: Forbidden
response headers: {'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json', 'X-RequestId': '6bb3ff58-8601-4552-b133-43d1e0a553a3', 'Set-Cookie': 'ARRAffinity=20358cd7aa5d6b0695f01ef171fc9a95880154357830e1c6bb513b73834a2e5f;Path=/;HttpOnly;Secure;Domain=doctrans.westus.microsofttranslator.com, ARRAffinitySameSite=20358cd7aa5d6b0695f01ef171fc9a95880154357830e1c6bb513b73834a2e5f;Path=/;HttpOnly;SameSite=None;Secure;Domain=doctrans.westus.microsofttranslator.com', 'X-Powered-By': 'ASP.NET', 'apim-request-id': '6bb3ff58-8601-4552-b133-43d1e0a553a3', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'x-content-type-options': 'nosniff', 'Date': 'Thu, 20 May 2021 22:56:45 GMT'}


Here's my Python code:

import requests

endpoint = "https://TrnDomain.cognitiveservices.azure.com/translator/text/batch/v1.0-preview.1"
subscriptionKey = ''
path = '/batches'
constructed_url = endpoint + path

payload= {
"inputs": [
{
"source": {
"sourceUrl": "https://cs2100320014388129a.blob.core.windows.net/",
"storageSource": "AzureBlob",
"language": "en"
"filter":{
"prefix": "sampleTest1",
"suffix": ".txt"
}

         },
         "targets": [
             {
                 "targetUrl": "https://cs2100320014388129a.blob.core.windows.net/",
                 "storageSource": "AzureBlob",
                 "category": "general",
                 "language": "fr"
             }
         ]
     }
 ]

}
headers = {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-Type': 'application/json'
}

response = requests.post(constructed_url, headers=headers, json=payload)

print(f'response status code: {response.status_code}\nresponse status: {response.reason}\nresponse headers: {response.headers}')



Appreciate any help you can provide!

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I think you are using the prefix and suffix to translate a specific document instead of filtering the documents with a folder name i.e by using prefix or a particular format i.e using suffix.
You can try this way to translate a document and check if this works.

  • Ensure you have specified "storageType": "File"

  • Ensure you have created source URL & SAS token for the specific blob/document (not for the container)

  • Ensure you have specified the target filename as part of the target URL – though the SAS token is still for the container.


0 Votes 0 ·

Hi Romungi-MSFT!

I tried your approach and still got the same error!

Do you think I need access permissions from Microsoft to use batch translator preview?

Thanks,
Tuan

0 Votes 0 ·

The service is now actually available directly and you need not request access. The only pre-reqs should be the [following][1]:

https://docs.microsoft.com/en-us/azure/cognitive-services/translator/document-translation/get-started-with-document-translation?tabs=python#prerequisites

  • Document Translation is currently supported in the Translator (single-service) resource only, and is not included in the Cognitive Services (multi-service) resource.

  • Document Translation is currently available in the S1 Standard Service Plan. See Cognitive Services pricing—Translator.



0 Votes 0 ·
Show more comments