谷歌云翻译在一个区域工作正常,在其他地方返回GoogleApiException

时间:2019-05-10 21:40:12

标签: google-translate

我们希望为我们的网站用户提供在邮件(组到)级别和个人级别上将其电子邮件翻译成其他语言的功能。

当时,我们选择电子邮件模板并分配接收电子邮件的个人组,同时还要分配语言。该代码会将消息正文翻译成指定的语言,然后将所有内容存储在表格中,以便以后通过电子邮件发送。效果很好。

var client = TranslateClient.Create();
var txtResponse = client.TranslateText(msg.MessageText, targetLanguage, sourceLanguage);
mtmg.MessageText = txtResponse.TranslatedText;

在处理表以发送电子邮件时,我们检查语言规范,如果匹配,则从表中发送已保存的msgbody,如果它们不同,则希望将原始内容转换为个人的语言规范,使用上面的相同代码,只是在我们网站的其他位置。

我已经创建了一个Google帐户。该代码已成功通过身份验证。我已经启用了谷歌云翻译api密钥,并赋予了它域范围的授权。我之所以这样说是因为它在我们的主应用程序中可以正常工作。我们创建了一个单独的应用程序来处理电子邮件,但它仍在同一域中(只是一个子应用程序)。电子邮件处理应用程序中的代码返回错误。

GoogleApiException:
>                       Event code: 3005

Event message: An unhandled exception has occurred.

Event time: 5/10/2019 2:25:14 PM

Event time (UTC): 5/10/2019 9:25:14 PM

Event ID: d3022bd40aca46dbb30779a26ef9dee3

Event sequence: 47

Event occurrence: 4

Event detail code: 0



Application information:

    Application domain: /LM/W3SVC/4/ROOT/email-9-132019961222642811

    Trust level: Full

    Application Virtual Path: /email

    Application Path: c:\000Becky\email\

    Machine name: DEVWEB



Process information:

    Process ID: 5152

    Process name: w3wp.exe

    Account name: IIS APPPOOL\BeckyAppPool



Exception information:

    Exception type: GoogleApiException

    Exception message: Google.Apis.Requests.RequestError
Invalid Value [400]
Errors [
    Message[Invalid Value] Location[ - ] Reason[invalid] Domain[global]
]

   at Google.Apis.Requests.ClientServiceRequest`1.<ParseResponse>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Google.Apis.Requests.ClientServiceRequest`1.Execute()
   at Google.Cloud.Translation.V2.TranslationClientImpl.TranslateText(IEnumerable`1 textItems, String targetLanguage, String sourceLanguage, Nullable`1 model)
   at Google.Cloud.Translation.V2.TranslationClient.TranslateText(String text, String targetLanguage, String sourceLanguage, Nullable`1 model)
   at TemplateProcessor.Process(Message e, String& title, Boolean send) in c:\000Becky\email\App_Code\TemplateProcessor.cs:line 193
   at TemplateProcessor.Process(Int32 MessageId, String& title, String& toAddr, String& status, Boolean& viewableOnline, Boolean send) in c:\000Becky\email\App_Code\TemplateProcessor.cs:line 453
   at _Default.Page_Load(Object sender, EventArgs e) in c:\000Becky\email\Default.aspx.cs:line 41
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)





Request information:

    Request URL: http://broof.emergencyuniversity.com/email/default.aspx?sa_id=1295075

    Request path: /email/default.aspx

    User host address: 174.224.13.206

    User: 

    Is authenticated: False

    Authentication Type: 

    Thread account name: IIS APPPOOL\BeckyAppPool



Thread information:

    Thread ID: 21

    Thread account name: IIS APPPOOL\BeckyAppPool

    Is impersonating: False

    Stack trace:    at Google.Apis.Requests.ClientServiceRequest`1.<ParseResponse>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Google.Apis.Requests.ClientServiceRequest`1.Execute()
   at Google.Cloud.Translation.V2.TranslationClientImpl.TranslateText(IEnumerable`1 textItems, String targetLanguage, String sourceLanguage, Nullable`1 model)
   at Google.Cloud.Translation.V2.TranslationClient.TranslateText(String text, String targetLanguage, String sourceLanguage, Nullable`1 model)
   at TemplateProcessor.Process(Message e, String& title, Boolean send) in c:\000Becky\email\App_Code\TemplateProcessor.cs:line 193
   at TemplateProcessor.Process(Int32 MessageId, String& title, String& toAddr, String& status, Boolean& viewableOnline, Boolean send) in c:\000Becky\email\App_Code\TemplateProcessor.cs:line 453
   at _Default.Page_Load(Object sender, EventArgs e) in c:\000Becky\email\Default.aspx.cs:line 41
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

如果消息和个人之间的语言规范匹配,则不会进行进一步的翻译,并且会使用正确的翻译正确发送消息。如果语言规范不匹配,并且运行了电子邮件处理器中的翻译代码,则会发生错误,并且不会发送电子邮件。

感谢您的见解!

0 个答案:

没有答案