无法连接到gateway.watsonplatform.net:443

时间:2015-10-20 13:23:27

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

我正在尝试运行示例java应用程序,如

所述

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

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

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

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

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

编辑: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

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

2 个答案:

答案 0 :(得分:2)

确保您拥有服务凭据,但未使用Bluemix usernamepassword

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

在本地运行个性见解

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

    import java.util.HashMap; import java.util.Map; import 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应用程序运行。

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

    enter image description here

答案 1 :(得分:0)

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

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