diff --git a/google/_async_resumable_media/requests/download.py b/google/_async_resumable_media/requests/download.py index 2b3e48ce..5b10e12e 100644 --- a/google/_async_resumable_media/requests/download.py +++ b/google/_async_resumable_media/requests/download.py @@ -90,7 +90,8 @@ async def _write_to_stream(self, response): self._stream.write(chunk) local_checksum_object.update(chunk) - if expected_checksum is not None: + # Don't validate the checksum for partial responses. + if expected_checksum is not None and response.status != 206: actual_checksum = sync_helpers.prepare_checksum_digest( checksum_object.digest() ) @@ -213,7 +214,8 @@ async def _write_to_stream(self, response): self._stream.write(chunk) checksum_object.update(chunk) - if expected_checksum is not None: + # Don't validate the checksum for partial responses. + if expected_checksum is not None and response.status != 206: actual_checksum = sync_helpers.prepare_checksum_digest( checksum_object.digest() ) diff --git a/google/resumable_media/requests/download.py b/google/resumable_media/requests/download.py index 88de223f..d202d56e 100644 --- a/google/resumable_media/requests/download.py +++ b/google/resumable_media/requests/download.py @@ -124,7 +124,8 @@ def _write_to_stream(self, response): self._bytes_downloaded += len(chunk) local_checksum_object.update(chunk) - if expected_checksum is not None: + # Don't validate the checksum for partial responses. + if expected_checksum is not None and response.status_code != 206: actual_checksum = _helpers.prepare_checksum_digest(checksum_object.digest()) if actual_checksum != expected_checksum: msg = _CHECKSUM_MISMATCH.format( @@ -308,7 +309,8 @@ def _write_to_stream(self, response): checksum_object.update(chunk) response._content_consumed = True - if expected_checksum is not None: + # Don't validate the checksum for partial responses. + if expected_checksum is not None and response.status_code != 206: actual_checksum = _helpers.prepare_checksum_digest(checksum_object.digest()) if actual_checksum != expected_checksum: