get java.net.SocketTimeoutException:运行视觉示例代码

时间:2017-01-10 02:38:58

标签: google-cloud-platform google-cloud-vision

我的项目有OCR要求,我想使用google云Vision API。我通过GIT下载示例代码,但报告跟踪错误:

  

线程中的异常" main" java.net.SocketTimeoutException:connect   超时于java.net.DualStackPlainSocketImpl.waitForConnect(Native   方法)at   java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)     在   java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)     在   java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)     在   java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)     在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)at   java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)at   java.net.Socket.connect(Socket.java:589)at   sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)at   sun.net.NetworkClient.doConnect(NetworkClient.java:175)at   sun.net.www.http.HttpClient.openServer(HttpClient.java:432)at   sun.net.www.http.HttpClient.openServer(HttpClient.java:527)at   sun.net.www.protocol.https.HttpsClient。(HttpsClient.java:264)     在sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)     在   sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)     在   sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)     在   sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)     在   sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)     在   sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)     在   sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)     在   sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)     在   com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)     在   com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)     在   com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283)     在   com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)     在   com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)     在   com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)     在   com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)     在   com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)     在   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)     在   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)     在   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)     在   com.google.cloud.vision.samples.label.LabelApp.labelImage(LabelApp.java:136)     在   com.google.cloud.vision.samples.label.LabelApp.main(LabelApp.java:71)

我不修改任何代码,我可以在API浏览器资源管理器上获得成功的测试结果。有没有人以前遇到过这类问题?能不能给我任何建议?

2 个答案:

答案 0 :(得分:1)

java.net.SocketTimeoutException表示在从远程主机收到响应之前连接超时。这几乎总是由本地网络问题或代理或防火墙配置引起的。

答案 1 :(得分:0)

我通过将代理模式设置为全局模式

来解决这个问题