Skip to content

Commit 4f11916

Browse files
committed
skip files which were uploaded completely, but the server did not return any response
1 parent 4272fc4 commit 4f11916

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
@@ -1096,6 +1101,21 @@ def _build_request():
10961101
print(' error uploading {0}: {1}'.format(key, msg), file=sys.stderr)
10971102
# Raise HTTPError with error message.
10981103
raise type(exc)(error_msg, response=exc.response, request=exc.request)
1104+
except ConnectionError as exc: # from requests
1105+
exc = exc.args[0]
1106+
if isinstance(exc, ProtocolError): # from urllib3
1107+
exc = exc.args[1]
1108+
if isinstance(exc, RemoteDisconnected): # from http.client
1109+
msg = ("The server closed the connection after the file was uploaded. "
1110+
"The upload might have succeeded anyway.")
1111+
error_msg = (' error uploading {0} to {1}, '
1112+
'{2}'.format(key, self.identifier, msg))
1113+
log.error(error_msg)
1114+
return Response()
1115+
else:
1116+
raise
1117+
else:
1118+
raise
10991119
finally:
11001120
body.close()
11011121

0 commit comments

Comments
 (0)