Skip to content

Commit

Permalink
skip files which were uploaded completely, but the server did not ret…
Browse files Browse the repository at this point in the history
…urn any response
  • Loading branch information
Dobatymo committed May 4, 2021
1 parent 202acff commit 875d9b3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion internetarchive/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@
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
try:
from http.client import RemoteDisconnected
except ImportError:
from httplib import BadStatusLine as RemoteDisconnected

from internetarchive.utils import IdentifierListAsItems, get_md5, chunk_generator, \
IterableToFileAdapter, iter_directory, recursive_file_count, norm_filepath
Expand Down Expand Up @@ -1098,6 +1103,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()

Expand Down

0 comments on commit 875d9b3

Please sign in to comment.