upload_5.py 925 B

123456789101112131415161718192021222324
  1. def recover(self, transport):
  2. """Recover from a failure.
  3. This method should be used when a :class:`ResumableUpload` is in an
  4. :attr:`~ResumableUpload.invalid` state due to a request failure.
  5. This will verify the progress with the server and make sure the
  6. current upload is in a valid state before :meth:`transmit_next_chunk`
  7. can be used again.
  8. Args:
  9. transport (~requests.Session): A ``requests`` object which can
  10. make authenticated requests.
  11. Returns:
  12. ~requests.Response: The HTTP response returned by ``transport``.
  13. """
  14. method, url, payload, headers = self._prepare_recover_request()
  15. # NOTE: We assume "payload is None" but pass it along anyway.
  16. result = _helpers.http_request(
  17. transport, method, url, data=payload, headers=headers,
  18. retry_strategy=self._retry_strategy)
  19. self._process_recover_response(result)
  20. return result