Cannot Connect to gateway.watsonplatform.net:443

▼魔方 西西 提交于 2019-12-11 13:31:32

问题


i am trying to run the sample java application as described on

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

i have been able to set up my liberty server properly and i have been able to create an app on the bluemix server with my account. When i try to run the sample code in Eclipse, i can see the watson q&a app interface. But when i hit the Ask button, i get

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

i have not made any changes to the code except putting in the values for the url of my service and the username and password.

Is there another system property i need to set?

Edit: manifest.yaml

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

also, when i run the command

cf marketplace -s question_and_answer

i see

service plan                    description   free or paid
question_and_answer_free_plan   Beta          free

is that correct?

Edit: Trying out the 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?"));
   }
}

but i still get

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

note that when i run

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

i get

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

is that consistent with the imports in my code?


回答1:


Make sure you have service credentials and you are not using your Bluemix username and password.

Since you want to use Personality-Insights I would suggest you to first start with a Main class and try to see that you have valid credentials

Running Personality Insights locally

  1. Download the Watson Developer Cloud Java SDK v1.1.1.
  2. In eclipse, create a java project(no web, plain java).
  3. Create a file and call it PersonalityInsightsExample.java.
  4. Copy the code below.

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

    public class 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. Replace username and password.

  6. Run it as a Java Application.


If you still get an error following the steps above then try opening a browser and going to: https://gateway.watsonplatform.net/personality-insights/api/v2/profile, you should get a password prompt.




回答2:


I had the same error tried using PersonalityInsightsExample suggested above, but seemed too complicated since, I found out that the problem was my network having to have proxy to be able to connect to foreign endpoints. So, just adding my proxy details fixed the problem:

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


来源:https://stackoverflow.com/questions/33237872/cannot-connect-to-gateway-watsonplatform-net443

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!