From 5225be866cb26eb0f895f7a5fce192f7c1a18073 Mon Sep 17 00:00:00 2001 From: Dobatymo Date: Fri, 11 Sep 2020 15:04:17 +0800 Subject: [PATCH] skip files which were uploaded completely, but the server did not return any response --- internetarchive/item.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/internetarchive/item.py b/internetarchive/item.py index 4a0dbd42..e228993e 100644 --- a/internetarchive/item.py +++ b/internetarchive/item.py @@ -46,7 +46,9 @@ from six.moves import urllib from requests import Response from tqdm import tqdm -from requests.exceptions import HTTPError +from requests.exceptions import HTTPError, ConnectionError +from urllib3.exceptions import ProtocolError +from http.client import RemoteDisconnected from internetarchive.utils import IdentifierListAsItems, get_md5, chunk_generator, \ IterableToFileAdapter, iter_directory, recursive_file_count, norm_filepath @@ -1007,6 +1009,21 @@ def _build_request(): print(' error uploading {0}: {1}'.format(key, msg), file=sys.stderr) # Raise HTTPError with error message. raise type(exc)(error_msg, response=exc.response, request=exc.request) + except ConnectionError as exc: # from requests + exc = exc.args[0] + if isinstance(exc, ProtocolError): # from urllib3 + exc = exc.args[1] + if isinstance(exc, RemoteDisconnected): # from http.client + msg = ("The server closed the connection after the file was uploaded. " + "The upload might have succeeded anyway.") + error_msg = (' error uploading {0} to {1}, ' + '{2}'.format(key, self.identifier, msg)) + log.error(error_msg) + return Response() + else: + raise + else: + raise finally: body.close()