gpt4 book ai didi

credentials - java.net.SocketTimeoutException : connect timed out + google directory , admin sdk API

转载 作者:行者123 更新时间:2023-12-05 04:16:36 27 4
gpt4 key购买 nike

我在使用服务帐户时遇到以下错误。 相同的代码在本地运行良好,并且我能够使用服务帐户创建凭据。

....Error Snapshot : 
aused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:270)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:327)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1090)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:269)

最佳答案

尝试以下...

  1. 在 linux box 中设置代理。
  2. 在创建存储时 - new NetHttpTransport() 提供您自己的方式来创建套接字并在传输中添加代理。

示例代码...

public HttpClient myHttpClient() throws Exception {

SchemeRegistry schemeRegistry = new SchemeRegistry();
//SetRegisrty for both HTTP and HTTPS - Check google for this.
schemeRegistry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), YOUR_PROXY_PORT));
schemeRegistry.register(new Scheme("https", SSLSocketFactory
.getSocketFactory(), 443));

HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 30 * 1000); // SET the timeout
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
ClientConnectionManager connManager = new ThreadSafeClientConnManager(
params, schemeRegistry);
DefaultHttpClient httpClient = new DefaultHttpClient(connManager,
params);
try {
int proxyPort = YOUR_PROXY_PORT;
String proxyHost = "YOUR_PROXT_HOST_NAME";
if (proxyPort > 0 && proxyHost != null && proxyHost.length() > 0) {
System.setProperty("https.proxyHost", proxyHost);
System.setProperty("https.proxyPort", proxyPort + "");
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort + "");
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
httpClient.getParams().setParameter(
ConnRoutePNames.DEFAULT_PROXY, proxy);
}
} catch (NullPointerException e) {
System.out.println("Proxy error here");
}
return httpClient;
}


public static HttpTransport myNetHttpTransport()
throws Exception {
return new ApacheHttpTransport(myHttpClient());
}

使用 .setTransport(myNetHttpTransport()) 而不是 NetHttpTransport() 。

我们在这上面花了很长时间。但截至目前,这似乎有效。如果有任何帮助,请告诉我...

关于credentials - java.net.SocketTimeoutException : connect timed out + google directory , admin sdk API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26749811/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com