java.net.SocketTimeoutException:在下载谷歌电子表格时读取超时

时间:2015-03-19 14:36:47

标签: java google-api google-drive-api google-sheets google-spreadsheet-api

我有一段代码可以下载谷歌电子表格

File file = service.files().get(spreadsheetID).execute();
String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl))
                .setConnectTimeout(0).execute();

默认情况下,连接超时为20秒。我试图将它设置为不同的值,但它不起作用。我一直在

  

引起:java.net.SocketTimeoutException:读取超时       at java.net.SocketInputStream.socketRead0(Native Method)〜[na:1.7.0_60]       在java.net.SocketInputStream.read(SocketInputStream.java:152)〜[na:1.7.0_60]       在java.net.SocketInputStream.read(SocketInputStream.java:122)〜[na:1.7.0_60]       at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)~ [na:1.7.0_60]       在sun.security.ssl.InputRecord.read(InputRecord.java:480)〜[na:1.7.0_60]       在sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)〜[na:1.7.0_60]       at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884)〜[na:1.7.0_60]       在sun.security.ssl.AppInputStream.read(AppInputStream.java:102)〜[na:1.7.0_60]       在java.io.BufferedInputStream.fill(BufferedInputStream.java:235)〜[na:1.7.0_60]       在java.io.BufferedInputStream.read1(BufferedInputStream.java:275)〜[na:1.7.0_60]       在java.io.BufferedInputStream.read(BufferedInputStream.java:334)〜[na:1.7.0_60]       在sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)〜[na:1.7.0_60]       在sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)〜[na:1.7.0_60]       at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)~ [na:1.7.0_60]       在java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)〜[na:1.7.0_60]       at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)〜[na:1.7.0_60]       在com.google.api.client.http.javanet.NetHttpResponse。(NetHttpResponse.java:36)〜[google-http-client-1.19.0.jar:1.19.0]       在com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94)〜[google-http-client-1.19.0.jar:1.19.0]       在com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)〜[google-http-client-1.19.0.jar:1.19.0]

1 个答案:

答案 0 :(得分:3)

你也需要setReadTimeout 可能文件太大了