Ibm cloud 无法连接到网关。watsonplatform.net:443

Ibm cloud 无法连接到网关。watsonplatform.net:443,ibm-cloud,ibm-watson,personality-insights,Ibm Cloud,Ibm Watson,Personality Insights,我正在尝试运行示例java应用程序,如中所述 我已经能够正确设置我的liberty服务器,并且能够使用我的帐户在bluemix服务器上创建应用程序。当我尝试在Eclipse中运行示例代码时,我可以看到watson q&a应用程序界面。但当我按下询问按钮时,我得到了 Error: Connect to gateway.watsonplatform.net:443 [gateway.watsonplatform.net/23.246.237.54] failed: Connection timed

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

我已经能够正确设置我的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
我明白了

对吗

编辑:尝试问题和回答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());
我明白了


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

请确保您拥有服务凭据,并且您没有使用Bluemix
用户名和密码

既然你想使用个性洞察,我建议你首先从一个主类开始,试着看看你是否有有效的凭证

在本地运行个性洞察
  • 下载
  • 在eclipse中,创建一个java项目(无web,纯java)
  • 创建一个文件并将其命名为
    PersonalityInsightExample.java
  • 复制下面的代码

    导入java.util.HashMap; 导入java.util.Map; 导入com.ibm.watson.developer\u cloud.personality\u insights.v2.model.Profile

    公共类个人旅游示例{

    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);
    }
    
    publicstaticvoidmain(字符串[]args){
    PersonalityInsights服务=新PersonalityInsights();
    service.setUserName和密码(“,”);
    String myProfile=“叫我以实玛利,几年前不管多久”
    +“我钱包里几乎没有钱,什么也没有”
    +“在岸上我特别感兴趣,我想我会四处航行”
    +“看一看世界上多水的地方。这是一种方式”
    +“我有驱除脾脏和调节血液循环的方法。”
    +“每当我发现自己的嘴变得冷酷无情;每当它”
    +“在我的灵魂里是一个潮湿、细雨蒙蒙的十一月;每当我发现自己”
    +“不由自主地停在棺材仓库前,提起”
    +“每次葬礼的背后,尤其是当我
    +“海波斯占了我的上风,这需要一个强有力的团队”
    +“防止我故意介入的道德原则”
    +“在街上,然后有条不紊地敲掉人们的帽子,”
    +“我认为是时候尽快出海了。”;
    Profile Profile=service.getProfile(myProfile);
    系统输出打印LN(配置文件);
    }
    
    }

  • 替换
    用户名
    密码

  • 将其作为Java应用程序运行


  • 如果在执行上述步骤后仍然出现错误,请尝试打开浏览器并转到:,您应该会收到密码提示


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

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

    你是想运行一个web应用程序,还是只是打电话给服务部门看看结果?因此,我的最终目标是向watson q&a服务提供一个自定义语料库,然后提问。这可行吗?我希望我可以通过java实现这一点。因此,我首先在bluemix服务器上创建了一个应用程序。接下来,我希望能够通过java调用应用程序中的服务。最后,我想输入我自己的语料库/数据集并查看结果。你还不能用你自己的语料库来训练QA。你必须将文档转换+检索和排名服务结合起来。哦,这太糟糕了。我将研究文档转换、检索和排序。这些也是华生的服务吗?谢谢但同时,如何解决连接超时问题?你知道是什么原因造成的吗?也许我的manifest.yaml没有设置正确的数据库,但我没有在bluemix上将Personal insights服务绑定到我的应用程序。我的应用程序的凭据在这里仍然有效吗?在Bluemix中创建一个Personal Insights服务,并从中获取
    用户名
    密码
    。这可能是一个问题,因为Personal Insights服务在我的计划中不是免费的。因此,我不允许在我的应用程序中使用它。我可以试着用这种方式连接问答服务吗?你可以在前200次API呼叫中免费使用Personal Insights服务。问题是你无法访问watson服务。我帮不了你:(
    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);
    }
    
    System.setProperty("http.proxyHost",HOST);
    System.setProperty("http.proxyPort",PORT);
    System.setProperty("https.proxyHost",HOST);
    System.setProperty("https.proxyPort",PORT);