The remote server returned an error: (400) Bad Request

2,032 views
Skip to first unread message

Venu Pappu

unread,
Jul 11, 2012, 11:36:27 PM7/11/12
to google-tra...@googlegroups.com

Hi All,

 

I am getting the error "the remote server returned an error: (400) Bad Request" while trying to make a translation request. Can anyone provide the possible reasons for the error?

 

Your help is greatly appreciated.

 

Regards,

Venu

João Martins

unread,
Jul 20, 2012, 10:49:32 AM7/20/12
to google-tra...@googlegroups.com
Venu, could you post here the code that you are using to make the call? Also, what is your numerical project ID?

Venu Pappu

unread,
Jul 21, 2012, 3:57:59 PM7/21/12
to google-tra...@googlegroups.com

Hi Joao,

 

Thanks for your reply. Please see below the .NET code that is making google translation call by passing chinse characters:

 


private string uri = "https://www.googleapis.com/language/translate/v2

private String messageFormat = "key={0}&q={1}&source={2}&target={3}";

public override string processResponse(String output, String message, string fromLanguage, string toLanguage)
        {
            object result = JsonResponse.Deserialize(output);
           
            //return JsonResponse.HtmlDecode(((Response<TranslatedText>)result).responseData.translatedText);

            return JsonResponse.HtmlDecode(((Response)result).Data.Translations[0].TranslatedText.ToString());
           
         }

The above function returns the JSON response with the English translation. The following is JSONResponse class:

public class JsonResponse

{
 public static object Deserialize(string Text)
 {
  Response myResult;
  MemoryStream ms = null;
  try
  {
   myResult =
   new Response();
   ms = new MemoryStream(Encoding.Unicode.GetBytes(Text));
   DataContractJsonSerializer serializer = new DataContractJsonSerializer(myResult.GetType());
   myResult = serializer.ReadObject(ms) as Response;

  }
  catch (Exception ex)
  {

   throw ex;
  }
  finally
  {
   if (ms != null)
   ms.Close();
  }

  return myResult;
 }

 public static string HtmlEncode(string text)
 {
  return System.Web.HttpUtility.HtmlEncode(text);

 }
 public static string HtmlDecode(string text)
 {
  return System.Web.HttpUtility.HtmlDecode(text);

 }
}

 

 

The above code is not working at the client site. The client has proxy server configured and the firewall rules have been set to accept only IP addresses and the names. The code was working with version 1 of Google translation API. the client had configured the firewall to accept the IP address 74.125.71.95 for Google. Can you please let me know the IP address or range of IP addresses for Google that I can provide the client?

 

The project Id for the client is 746355742018. Please let me know if you need anything.

Would appreciate your early response.

 

Thanks

Venu

João Martins

unread,
Jul 23, 2012, 4:47:56 AM7/23/12
to google-tra...@googlegroups.com
Venu, to know the IP address range for Google, follow this link. Make sure that the firewall includes these addresses and that your referrer contains the IP from the server you are sending the request. Then, let me know if it still does not work for you.

Venu Pappu

unread,
Jul 23, 2012, 9:09:14 AM7/23/12
to google-tra...@googlegroups.com
Hi Joao,
 
Thanks for your reply. Based on the error message, what could be the reason for the errors As mentioned, this happens only at the client. I have run the command to get the range of IP addresses, I am not sure which of the following pertains to Google translation servers:
 
 
Is everything OK with the way I am making the call for the translation request.
 
Thanks for you help.
 
Regards,
Venu
 

João Martins

unread,
Jul 23, 2012, 12:47:57 PM7/23/12
to google-tra...@googlegroups.com
Venu, everything looks great with your code. You should be careful to make a POST request instead of GET if your text is too long and doesn't fit inside the maximum request.
There are no guarantees about where your request is addressed to, so you should make a list for that list of adress ranges.
What do you mean with this issue only happening at the client?

I would also advise that you try to call Translate API using a key with every allowed referrer a first time and let me know if that works.
Reply all
Reply to author
Forward
0 new messages