Не удалось подключиться к платформе Watson - PullRequest
0 голосов
/ 20 декабря 2018

У меня проблемы с использованием IBM Language Translator.Я продолжаю получать исключение java.net.ConnectException.Моя платформа - Windows 10, и я использую Eclipse Photon.Я отключил брандмауэр и антивирусную программу.Ниже приведен мой код:

import java.util.ArrayList;
import java.util.List;

import com.ibm.watson.developer_cloud.language_translator.v3.LanguageTranslator;
import com.ibm.watson.developer_cloud.language_translator.v3.model.TranslateOptions;
import com.ibm.watson.developer_cloud.language_translator.v3.model.Translation;
import com.ibm.watson.developer_cloud.language_translator.v3.model.TranslationResult;
import com.ibm.watson.developer_cloud.language_translator.v3.util.Language;

class IBMTest {
    public static void main(String[] args) {
        LanguageTranslator service = new LanguageTranslator("2018-05-01");

        service.setApiKey("...apikey...");
        String textToTranslate = "Αυτοκινητόδρομος";
        List<String> text = new ArrayList<>();
        text.add(textToTranslate);

        TranslateOptions translateOptions = new TranslateOptions.Builder().text(text).source(Language.GREEK)
                .target(Language.ENGLISH).build();
        TranslationResult firstResult = service.translate(translateOptions).execute();

        List<Translation> translations = firstResult.getTranslations();
        if (translations.size() > 1) {
            System.out.println("There are multiple translations:");
            for (Translation nextTranslation : translations) {
                System.out.println("- " + nextTranslation);
            }
        }
    }
}

Приложение вызывает исключение по адресу:

TranslationResult firstResult = service.translate(translateOptions).execute();

Следующее исключение:

Exception in thread "main" java.lang.RuntimeException: java.net.ConnectException: Failed to connect to gateway-a.watsonplatform.net/54.209.159.70:443
    at com.ibm.watson.developer_cloud.service.WatsonService$WatsonServiceCall.execute(WatsonService.java:534)
    at com.packt.javanlp.cookbook.chapter.IBM.main(IBM.java:50)
    at com.packt.javanlp.cookbook.chapter.IBM.main(IBM.java:35)
Caused by: java.net.ConnectException: Failed to connect to gateway-a.watsonplatform.net/54.209.159.70:443
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165)
    at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
    at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at com.ibm.watson.developer_cloud.service.WatsonService$WatsonServiceCall.execute(WatsonService.java:531)
    ... 2 more
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.base/java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.base/java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.base/java.net.PlainSocketImpl.connect(Unknown Source)
    at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
    at java.base/java.net.Socket.connect(Unknown Source)
    at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129)
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245)
    ... 20 more

1 Ответ

0 голосов
/ 20 декабря 2018

Кажется, не проблема Java.Я только что проверил и попытался подключиться к вашему серверу через TCP:

telnet 54.209.159.70 443
.... connection timeout

Я думаю, вы должны проверить свои настройки - см. https://cloud.ibm.com/apidocs/language-translator

...