Code Monkey home page Code Monkey logo

Comments (3)

strongant avatar strongant commented on June 17, 2024

how to resolve this ?

from fake-s3.

strongant avatar strongant commented on June 17, 2024

def monkey_patch_boto():
from boto.exception import PleaseRetryException

def should_retry(self, response, chunked_transfer=False):
    provider = self.bucket.connection.provider

    if not chunked_transfer:
        if response.status in [500, 503]:
            # 500 & 503 can be plain retries.
            return True

        if response.getheader('location'):
            # If there's a redirect, plain retry.
            return True

    if 200 <= response.status <= 299:
        self.etag = response.getheader('etag')
        md5 = self.md5
        if isinstance(md5, bytes):
            md5 = md5.decode('utf-8')

        # If you use customer-provided encryption keys, the ETag value that
        # Amazon S3 returns in the response will not be the MD5 of the
        # object.
        server_side_encryption_customer_algorithm = response.getheader(
            'x-amz-server-side-encryption-customer-algorithm', None)
        if server_side_encryption_customer_algorithm is None:
            if self.etag != '"%s"' % md5 and self.etag != md5:
                raise provider.storage_data_error(
                    'ETag from S3 did not match computed MD5. '
                    '%s vs. %s' % (self.etag, self.md5))

        return True

    if response.status == 400:
        # The 400 must be trapped so the retry handler can check to
        # see if it was a timeout.
        # If ``RequestTimeout`` is present, we'll retry. Otherwise, bomb
        # out.
        body = response.read()
        err = provider.storage_response_error(
            response.status,
            response.reason,
            body
        )

        if err.error_code in ['RequestTimeout']:
            raise PleaseRetryException(
                "Saw %s, retrying" % err.error_code,
                response=response
            )

    return False
Key.should_retry = should_retry

from fake-s3.

strongant avatar strongant commented on June 17, 2024

example:
monkey_patch_boto()

connection = S3Connection(S3_ACCESSED_ID,
                          S3_SECRECT_ACCESS_KEY,
                          host=S3_HOST,is_secure=False)
print connection.connection
b = connection.get_bucket("result")
print b
k = Key(b)
tkey = "forbar".encode("utf-8")
k.key = tkey
print k.md5
print k.etag
md5str = hashlib.md5('hello'.strip()).hexdigest()
print md5str
k.set_contents_from_string(tkey)
print  k.get_contents_as_string()

have a try?

from fake-s3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.