Skip to content

Commit c60e581

Browse files
committed
skip files which were uploaded completely, but the server did not return any response
1 parent 55431a5 commit c60e581

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

internetarchive/item.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@
4646
from six.moves import urllib
4747
from requests import Response
4848
from tqdm import tqdm
49-
from requests.exceptions import HTTPError
49+
from requests.exceptions import HTTPError, ConnectionError
50+
from urllib3.exceptions import ProtocolError
51+
try:
52+
from http.client import RemoteDisconnected
53+
except ImportError:
54+
from httplib import BadStatusLine as RemoteDisconnected
5055

5156
from internetarchive.utils import IdentifierListAsItems, get_md5, chunk_generator, \
5257
IterableToFileAdapter, iter_directory, recursive_file_count, norm_filepath
@@ -1104,6 +1109,21 @@ def _build_request():
11041109
print(' error uploading {0}: {1}'.format(key, msg), file=sys.stderr)
11051110
# Raise HTTPError with error message.
11061111
raise type(exc)(error_msg, response=exc.response, request=exc.request)
1112+
except ConnectionError as exc: # from requests
1113+
exc = exc.args[0]
1114+
if isinstance(exc, ProtocolError): # from urllib3
1115+
exc = exc.args[1]
1116+
if isinstance(exc, RemoteDisconnected): # from http.client
1117+
msg = ("The server closed the connection after the file was uploaded. "
1118+
"The upload might have succeeded anyway.")
1119+
error_msg = (' error uploading {0} to {1}, '
1120+
'{2}'.format(key, self.identifier, msg))
1121+
log.error(error_msg)
1122+
return Response()
1123+
else:
1124+
raise
1125+
else:
1126+
raise
11071127
finally:
11081128
body.close()
11091129

0 commit comments

Comments
 (0)