question

NealeFaunt-1511 avatar image
0 Votes"
NealeFaunt-1511 asked SathyamoorthyVijayakumar-MSFT answered

Microsoft Translator receiving error 405000, "The request method is not supported for the requested resource."

I'm receiving this error using C# module that had previously been working for months. Using the following endpoint:

https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" -H "Ocp-Apim-Subscription-Key: <client-secret>" -H "Content-Type: application/json; charset=UTF-8" -d "[{'Text':'Hello, what is your name?'}]

Resource is global on paid Azure subscriptions. I regenerated the keys within Azure and inserted as the new key. Did something change that resulted in this not working?

azure-translator
· 5
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.

Where is your code hosted. Is the machine using the code using TLS 1.2 ? All the cognitive services are enforced with TLS 1.2 and require TLS 1.2 to function.

The below is a simple Powershell script. Recommend you to test the below script on a different machine (a machine which has tls1.2 enabled - like windows 10 machine ) with your subscription key and see whether you are able to get the results.

 $headers = @{"Ocp-Apim-Subscription-Key" = "<YOUR SUBSCRIPTION KEY>";"Content-Type"= "application/json";"charset"="UTF-8"}
 $response = Invoke-WebRequest -Uri "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" -Headers $headers -Body "[{'Text':'Hello, what is your name?'}]" -Method Post 
 $response.Content

0 Votes 0 ·

Also, when I was testing the behavior at my end, I was able to partially reproduce the issue at my end when the VERB was PUT (not POST). This may or may not be your case but wanted to highlight and it is safer to confirm the HTTP Verb (GET,PUT,POST etc) you are making use of.

Request :
95255-image.png

Response :
95256-image.png

0 Votes 0 ·
image.png (4.1 KiB)
image.png (3.1 KiB)
NealeFaunt-1511 avatar image NealeFaunt-1511 SathyamoorthyVijayakumar-MSFT ·

Hi Sathyamoorthy,

Thanks for getting back so quickly. Yes, I can confirm the Windows machine runs TLS 1.2. I've run the script and getting an error. The HTTP Verb used is "POST". I've included some screenshots showing script result, and my code.

Note, this code had run successfully for over a year prior to receiving the error sometime in April. No changes to my environment were made.

95342-autotranslatetroubleshoot.jpg95308-translationcode.jpg

0 Votes 0 ·

Strange. Can you pls run the below set of command in your machine. (If possible, can you run on a network in which there are less restriction ? )
This enforces to use TLS12

 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
 $headers = @{"Ocp-Apim-Subscription-Key" = "<Your Subscription key>";"Content-Type"= "application/json";"charset"="UTF-8"}
 $response = Invoke-WebRequest -Uri "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" -Headers $headers -Body "[{'Text':'Hello, what is your name?'}]" -Method Post 
0 Votes 0 ·
Show more comments

1 Answer

SathyamoorthyVijayakumar-MSFT avatar image
1 Vote"
SathyamoorthyVijayakumar-MSFT answered

The powershell error looked more like a network error. So I had suggested running the below command :

 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  $headers = @{"Ocp-Apim-Subscription-Key" = "<Your Subscription key>";"Content-Type"= "application/json";"charset"="UTF-8"}
  $response = Invoke-WebRequest -Uri "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" -Headers $headers -Body "[{'Text':'Hello, what is your name?'}]" -Method Post 


The code [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 enforces to make use of the TLS 1.2. As mentioned in this article, Cognitive Services endpoints exposed over HTTP enforce TLS 1.2.

Translated code ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; helped you to resolve your Issue.




Please do not forget to "Accept the answer" wherever the information provided helps you. This will help others in the community as well.




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.