Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip files which were uploaded completely, but the server did not return any response #372

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion internetarchive/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
from urllib.parse import quote
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,
Expand Down Expand Up @@ -1071,6 +1076,21 @@ def _build_request():
print(f' error uploading {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