【问题标题】:java.net.ConnectException when trying to connect watson toneanalyser in java spring尝试在 java spring 中连接 watson 音调分析器时出现 java.net.ConnectException
【发布时间】:2023-04-03 08:30:02
【问题描述】:

我正在使用 watson 音调分析器来检测文本中的主要音调。我在 android 中得到结果,但在 java spring 中,当我调用 get Tone 函数时出现以下错误。

错误日志

 HTTP Status 500 - Request processing failed; nested exception is java.lang.RuntimeException: java.net.ConnectException: Failed to connect to gateway.watsonplatform.net/169.48.66.222:443
 type Exception report

  message Request processing failed; nested exception is java.lang.RuntimeException: java.net.ConnectException: Failed to connect to gateway.watsonplatform.net/169.48.66.222:443

 description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.RuntimeException: java.net.ConnectException: Failed to connect to gateway.watsonplatform.net/169.48.66.222:443
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause

java.lang.RuntimeException: java.net.ConnectException: Failed to connect to gateway.watsonplatform.net/169.48.66.222:443
com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:176)
com.futuro.textmining.controller.MyController.getDominantEmotion(MyController.java:55)
com.futuro.textmining.controller.MyController.loadIndexLogin(MyController.java:86)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)

我的代码

 private String getDominantEmotion(String text){
     final String VERSION_DATE = "2018-02-14";
     ToneAnalyzer toneAnalyzer = new ToneAnalyzer(VERSION_DATE);
 toneAnalyzer.setUsernameAndPassword("80ff86fc-1329-46c1-9b51-45dda8d987e9", "WnQUuZcjVfLP");

      ToneOptions options = new ToneOptions.Builder().text(text).sentences(false).build();
        DocumentAnalysis documentAnalysis = toneAnalyzer.tone(options).execute().getDocumentTone();
        List<ToneScore> toneScores = documentAnalysis.getToneCategories().get(0).getTones();

        double maxScore = toneScores.get(0).getScore();
        String dominantTone = toneScores.get(0).getToneId();
        for(ToneScore toneScore : toneScores){
            if(toneScore.getScore() > maxScore){
                maxScore = toneScore.getScore();
                dominantTone = toneScore.getToneName();
            }
      }

     return dominantTone;
 }

【问题讨论】:

    标签: java watson


    【解决方案1】:

    我通过关闭有助于访问 API 的防火墙和防病毒软件解决了这个问题。可能对寻找相同的人有用

    【讨论】:

      猜你喜欢
      • 2017-08-24
      • 2015-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      相关资源
      最近更新 更多