【问题标题】:Cannot Connect to gateway.watsonplatform.net:443无法连接到 gateway.watsonplatform.net:443
【发布时间】:2015-10-20 13:23:26
【问题描述】:

我正在尝试按照上面的描述运行示例 java 应用程序

https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/getting_started/gs-full-java.shtml

我已经能够正确设置我的 liberty 服务器,并且我已经能够使用我的帐户在 bluemix 服务器上创建一个应用程序。当我尝试在 Eclipse 中运行示例代码时,我可以看到 watson q&a 应用程序界面。但是当我点击询问按钮时,我得到了

Error: Connect to gateway.watsonplatform.net:443 [gateway.watsonplatform.net/23.246.237.54] failed: Connection timed out: connect

除了输入我的服务的 url 以及用户名和密码的值之外,我没有对代码进行任何更改。

我需要设置另一个系统属性吗?

编辑:manifest.yaml

applications:
 - services:
  - question_and_answer
  name: myDumbApp
  path: webApp.war
  memory: 512M

还有,当我运行命令时

cf marketplace -s question_and_answer

我明白了

service plan                    description   free or paid
question_and_answer_free_plan   Beta          free

对吗?

编辑:试用 QuestionAndAnswer api

import java.util.HashMap;
import java.util.Map;

import com.ibm.watson.developer_cloud.personality_insights.v2.PersonalityInsights;
import com.ibm.watson.developer_cloud.personality_insights.v2.model.Profile;
import com.ibm.watson.developer_cloud.question_and_answer.*;
import com.ibm.watson.developer_cloud.question_and_answer.v1.QuestionAndAnswer;
import com.ibm.watson.developer_cloud.question_and_answer.v1.model.QuestionAndAnswerDataset;

public class PersonalityInsightsExample {
public static void main(String[] args) {

    QuestionAndAnswer qas = new QuestionAndAnswer();
    qas.setUsernameAndPassword("uName", "Pass");
    QuestionAndAnswerDataset qd = new QuestionAndAnswerDataset("TRAVEL");

    /*
    PersonalityInsights service = new PersonalityInsights();
    service.setUsernameAndPassword("uName", "Pass");

    String myProfile = "Call me Ishmael. Some years ago-never mind how long "
            + "precisely-having little or no money in my purse, and nothing "
            + "particular to interest me on shore, I thought I would sail about "
            + "a little and see the watery part of the world. It is a way "
            + "I have of driving off the spleen and regulating the circulation. "
            + "Whenever I find myself growing grim about the mouth; whenever it "
            + "is a damp, drizzly November in my soul; whenever I find myself "
            + "involuntarily pausing before coffin warehouses, and bringing up "
            + "the rear of every funeral I meet; and especially whenever my "
            + "hypos get such an upper hand of me, that it requires a strong "
            + "moral principle to prevent me from deliberately stepping into "
            + "the street, and methodically knocking people's hats off-then, "
            + "I account it high time to get to sea as soon as I can.";


    Profile profile = service.getProfile(myProfile);
      */

    qas.setDataset(qd);

    System.out.println( qas.ask("How to get cold?"));
   }
}

但我还是得到了

SEVERE: IOException
org.apache.http.conn.HttpHostConnectException: Connection to https://gateway.watsonplatform.net refused

请注意,当我运行时

 System.out.println(qas.getEndPoint());

我明白了

https://gateway.watsonplatform.net/question-and-answer-beta/api

这与我代码中的导入一致吗?

【问题讨论】:

  • 您是想运行一个网络应用还是只调用服务并查看结果?
  • 所以,我的最终目标是将自定义语料库提供给 watson 问答服务,然后提出问题。这可行吗?我希望我可以通过java做到这一点。因此,我首先在 bluemix 服务器上创建了一个应用程序。接下来我希望能够通过java调用我的应用程序中的服务。最后,我想提供我自己的语料库/数据集并查看结果。
  • 您还不能使用自己的语料库训练 QA。您必须通过结合文档转换 + 检索和排名服务来做到这一点。
  • 哦,那真是太糟糕了。我将研究文档转换并检索和排名。这些也是 Watson 服务吗?谢谢。但与此同时,我该如何解决连接超时?知道是什么原因造成的吗?
  • 可能我的 manifest.yaml 设置不正确

标签: ibm-cloud ibm-watson personality-insights


【解决方案1】:

确保您拥有服务凭证并且您没有使用您的 Bluemix usernamepassword

由于您想使用 Personality-Insights,我建议您首先从 Main 类开始,并尝试查看您是否拥有有效的凭据

在本地运行 Personality Insights

  1. 下载Watson Developer Cloud Java SDK v1.1.1
  2. 在 Eclipse 中,创建一个 java 项目(无 web,纯 java)。
  3. 创建一个文件并将其命名为PersonalityInsightsExample.java
  4. 复制下面的代码。

    导入 java.util.HashMap; 导入 java.util.Map; 导入 com.ibm.watson.developer_cloud.personality_insights.v2.model.Profile;

    公开课 PersonalityInsightsExample {

    public static void main(String[] args) {
        PersonalityInsights service = new PersonalityInsights();
        service.setUsernameAndPassword("<username>", "<password>");
    
        String myProfile = "Call me Ishmael. Some years ago-never mind how long "
                + "precisely-having little or no money in my purse, and nothing "
                + "particular to interest me on shore, I thought I would sail about "
                + "a little and see the watery part of the world. It is a way "
                + "I have of driving off the spleen and regulating the circulation. "
                + "Whenever I find myself growing grim about the mouth; whenever it "
                + "is a damp, drizzly November in my soul; whenever I find myself "
                + "involuntarily pausing before coffin warehouses, and bringing up "
                + "the rear of every funeral I meet; and especially whenever my "
                + "hypos get such an upper hand of me, that it requires a strong "
                + "moral principle to prevent me from deliberately stepping into "
                + "the street, and methodically knocking people's hats off-then, "
                + "I account it high time to get to sea as soon as I can.";
    
        Profile profile = service.getProfile(myProfile);
        System.out.println(profile);
    }
    

    }

  5. 替换usernamepassword

  6. 将其作为 Java 应用程序运行。


如果执行上述步骤后仍然出现错误,请尝试打开浏览器并转到:https://gateway.watsonplatform.net/personality-insights/api/v2/profile,您应该会收到密码提示。

【讨论】:

  • 谢谢,但我在 bluemix 上没有绑定到我的应用程序的个性洞察服务。我的应用程序的凭据仍然可以在这里使用吗?
  • 在 Bluemix 中创建 Personality Insights 服务并从中获取 usernamepassoword
  • 这可能是个问题,因为个性洞察服务在我的计划中不是免费的。因此我不允许在我的应用程序中使用它。我可以尝试以这种方式连接到问答服务吗?
  • 前 200 次 API 调用可以免费使用 Personality Insights 服务
  • 问题是您无法访问 watson 服务。我帮不了你:(
【解决方案2】:

我尝试使用上面建议的 PersonalityInsightsExample 时遇到了同样的错误,但似乎太复杂了,因为我发现问题是我的网络必须有代理才能连接到外部端点。因此,只需添加我的代理详细信息即可解决问题:

System.setProperty("http.proxyHost",HOST);
System.setProperty("http.proxyPort",PORT);
System.setProperty("https.proxyHost",HOST);
System.setProperty("https.proxyPort",PORT);

【讨论】:

    猜你喜欢
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2013-08-23
    • 2016-03-23
    • 2011-12-03
    相关资源
    最近更新 更多