Skip to content

Commit 9ea5e2d

Browse files
committed
Catch ECONNRESET and other errors more reliably
1 parent 70bc6c9 commit 9ea5e2d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

googleapiclient/http.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@
2828
from six import BytesIO, StringIO
2929
from six.moves.urllib.parse import urlparse, urlunparse, quote, unquote
3030

31-
import base64
3231
import copy
33-
import gzip
3432
import httplib2
3533
import json
3634
import logging
3735
import mimetypes
3836
import os
3937
import random
4038
import socket
41-
import sys
4239
import time
4340
import uuid
4441

@@ -190,11 +187,16 @@ def _retry_request(
190187
exception = connection_error
191188
except socket.error as socket_error:
192189
# errno's contents differ by platform, so we have to match by name.
190+
# Some of these same errors may have been caught above, e.g. ECONNRESET *should* be
191+
# raised as a ConnectionError, but some libraries will raise it as a socket.error
192+
# with an errno corresponding to ECONNRESET
193193
if socket.errno.errorcode.get(socket_error.errno) not in {
194194
"WSAETIMEDOUT",
195195
"ETIMEDOUT",
196196
"EPIPE",
197197
"ECONNABORTED",
198+
"ECONNREFUSED",
199+
"ECONNRESET",
198200
}:
199201
raise
200202
exception = socket_error

0 commit comments

Comments
 (0)