当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.ReadTimeoutError方法代码示例

本文整理汇总了Python中botocore.exceptions.ReadTimeoutError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ReadTimeoutError方法的具体用法?Python exceptions.ReadTimeoutError怎么用?Python exceptions.ReadTimeoutError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在botocore.exceptions的用法示例。


在下文中一共展示了exceptions.ReadTimeoutError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import ReadTimeoutError [as 别名]
def read(self, amt=None):
        """Read at most amt bytes from the stream.

        If the amt argument is omitted, read all data.
        """
        try:
            chunk = self._raw_stream.read(amt)
        except URLLib3ReadTimeoutError as e:
            # TODO: the url will be None as urllib3 isn't setting it yet
            raise ReadTimeoutError(endpoint_url=e.url, error=e)
        self._amount_read += len(chunk)
        if amt is None or (not chunk and amt > 0):
            # If the server sends empty contents or
            # we ask to read all of the contents, then we know
            # we need to verify the content length.
            self._verify_content_length()
        return chunk 
开发者ID:QData,项目名称:deepWordBug,代码行数:19,代码来源:response.py

示例2: test_connector_timeout2

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import ReadTimeoutError [as 别名]
def test_connector_timeout2():
    session = AioSession()
    config = AioConfig(max_pool_connections=1, connect_timeout=1,
                       read_timeout=1, retries={'max_attempts': 0})
    async with AIOServer() as server, \
            session.create_client('s3', config=config,
                                  endpoint_url=server.endpoint_url,
                                  aws_secret_access_key='xxx',
                                  aws_access_key_id='xxx') as s3_client:

        with pytest.raises(ReadTimeoutError):
            resp = await s3_client.get_object(Bucket='foo', Key='bar')
            await resp["Body"].read() 
开发者ID:aio-libs,项目名称:aiobotocore,代码行数:15,代码来源:test_config.py

示例3: commit

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import ReadTimeoutError [as 别名]
def commit(self):
        for key, value in self._dirty_rows.items():
            key_schema = self._convert_key_to_key_schema(key)

            if LOGGER_DEBUG_ENABLED:
                # Guard json.dumps calls due to its expensive computation
                LOGGER.debug(
                    'LookupTable (%s): Updating key \'%s\' with schema (%s)',
                    self.id,
                    key,
                    json.dumps(key_schema)
                )

            try:
                item = key_schema
                item[self._dynamo_db_value_key] = value

                put_item_args = {
                    'Item': item,
                }

                if LOGGER_DEBUG_ENABLED:
                    put_item_args['ReturnConsumedCapacity'] = 'TOTAL'

                # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services
                #       /dynamodb.html#DynamoDB.Table.put_item
                self._table.put_item(**put_item_args)
                self._cache.set(key, value, self._cache_refresh_minutes)

            except (ClientError, ConnectTimeoutError, ReadTimeoutError):
                raise LookupTablesInitializationError(
                    'LookupTable ({}): Failure to set key'.format(self.id)
                )

        self._dirty_rows = {} 
开发者ID:airbnb,项目名称:streamalert,代码行数:37,代码来源:driver_dynamodb.py

示例4: upload

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import ReadTimeoutError [as 别名]
def upload(self, bytes_data):
        """
        Params:
            bytes_data (bytes)
        """
        try:
            self._s3_client.Bucket(self._s3_bucket).put_object(
                Key=self._s3_key,
                Body=bytes_data
            )
            LOGGER.debug(
                'LookupTable (%s): Object successfully uploaded to S3',
                self._driver.id
            )
        except ClientError as err:
            LOGGER.error(
                'LookupTable (%s): Failed to upload to S3. Error message: %s',
                self._driver.id,
                err.response['Error']['Message']
            )
            raise LookupTablesCommitError(
                'LookupTable S3 Driver Failed with Message: {}'.format(
                    err.response['Error']['Message']
                )
            )
        except (ConnectTimeoutError, ReadTimeoutError):
            # Catching ConnectTimeoutError and ReadTimeoutError from botocore
            LOGGER.error(
                'LookupTable (%s): Reading from S3 timed out',
                self._driver.id
            )
            raise LookupTablesCommitError(
                'LookupTable ({}): Reading from S3 timed out'.format(self._driver.id)
            ) 
开发者ID:airbnb,项目名称:streamalert,代码行数:36,代码来源:driver_s3.py

示例5: test_botocore_read_timeout

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import ReadTimeoutError [as 别名]
def test_botocore_read_timeout(self, mock_logger, boto_resource_fn_mock):
        """LookupTables - Drivers - DynamoDB Driver - Get - ReadTimeoutError"""
        boto_resource_fn_mock.return_value.Table.return_value.get_item.side_effect = \
            ReadTimeoutError(
                'TestPool', 'Test Read timed out.', endpoint_url='test/url'
            )

        self._driver.initialize()

        assert_raises(LookupTablesInitializationError, self._driver.get, 'bbbb:1')

        mock_logger.assert_any_call(
            'LookupTable (%s): Reading from DynamoDB timed out',
            'dynamodb:table_name'
        ) 
开发者ID:airbnb,项目名称:streamalert,代码行数:17,代码来源:test_driver_dynamodb.py

示例6: _load

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import ReadTimeoutError [as 别名]
def _load(self, key):
        key_schema = self._convert_key_to_key_schema(key)

        if LOGGER_DEBUG_ENABLED:
            # Guard json.dumps calls due to its expensive computation
            LOGGER.debug(
                'LookupTable (%s): Loading key \'%s\' with schema (%s)',
                self.id,
                key,
                json.dumps(key_schema)
            )

        try:
            get_item_args = {
                'Key': key_schema,
                # It's not urgently vital to do consistent reads; we accept that for some time we
                # may get out-of-date reads.
                'ConsistentRead': False,

                # FIXME (derek.wang) This should have a ProjectionExpression to prevent the
                #  response from returning irrelevant fields.
            }

            if LOGGER_DEBUG_ENABLED:
                get_item_args['ReturnConsumedCapacity'] = 'TOTAL'

            # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services
            #       /dynamodb.html#DynamoDB.Table.get_item
            response = self._table.get_item(**get_item_args)

        except (ConnectTimeoutError, ReadTimeoutError):
            # Catching timeouts
            LOGGER.error(
                'LookupTable (%s): Reading from DynamoDB timed out',
                self.id
            )
            raise LookupTablesInitializationError(
                'LookupTable ({}): Reading from DynamoDB timed out'.format(self.id)
            )

        if 'Item' not in response:
            self._cache.set_blank(key, self._cache_refresh_minutes)
            return

        if self._dynamo_db_value_key not in response['Item']:
            self._cache.set_blank(key, self._cache_refresh_minutes)
            LOGGER.error(
                'LookupTable (%s): Requested value key %s seems to be missing from the table.',
                self.id,
                self._dynamo_db_value_key
            )
            return

        self._cache.set(
            key,
            response['Item'][self._dynamo_db_value_key],
            self._cache_refresh_minutes
        ) 
开发者ID:airbnb,项目名称:streamalert,代码行数:60,代码来源:driver_dynamodb.py

示例7: download

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import ReadTimeoutError [as 别名]
def download(self):
        """
        Return: bytes
        """
        try:
            start_time = time.time()
            s3_object = self._s3_client.Object(self._s3_bucket, self._s3_key).get()
            bytes_data = s3_object.get('Body').read()

            total_time = time.time() - start_time
            size_kb = round(s3_object.get('ContentLength') / 1024.0, 2)
            size_mb = round(size_kb / 1024.0, 2)
            LOGGER.debug(
                'LookupTable (%s): Downloaded S3 file size %s in %s seconds',
                self._driver.id,
                '{}MB'.format(size_mb) if size_mb else '{}KB'.format(size_kb),
                round(total_time, 2)
            )

            return bytes_data
        except ClientError as err:
            LOGGER.error(
                'LookupTable (%s): Encountered error while downloading %s from %s: %s',
                self._driver.id,
                self._s3_key,
                self._s3_bucket,
                err.response['Error']['Message']
            )
            raise LookupTablesInitializationError(
                'LookupTable S3 Driver Failed with Message: {}'.format(
                    err.response['Error']['Message']
                )
            )

        except (ConnectTimeoutError, ReadTimeoutError):
            # Catching ConnectTimeoutError and ReadTimeoutError from botocore
            LOGGER.error(
                'LookupTable (%s): Reading from S3 timed out',
                self._driver.id
            )
            raise LookupTablesInitializationError(
                'LookupTable ({}): Reading from S3 timed out'.format(self._driver.id)
            ) 
开发者ID:airbnb,项目名称:streamalert,代码行数:45,代码来源:driver_s3.py


注:本文中的botocore.exceptions.ReadTimeoutError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。