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


Python exceptions.NoRegionError方法代码示例

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


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

示例1: _get_client

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def _get_client(
        self, client_type, region_name, profile_name, boto_client_kwargs
    ):
        session_kwargs = {}
        if region_name is not None:
            session_kwargs['region_name'] = region_name

        if profile_name is not None:
            session_kwargs['profile_name'] = profile_name

        client_kwargs = boto_client_kwargs or {}

        session = boto3.session.Session(**session_kwargs)
        try:
            boto_client = session.client(client_type, **client_kwargs)
        except NoRegionError:
            boto_client = session.client(
                client_type, region_name=DEFAULT_REGION_NAME, **client_kwargs
            )

        return boto_client 
开发者ID:obsrvbl,项目名称:flowlogs-reader,代码行数:23,代码来源:flowlogs_reader.py

示例2: main

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def main(args=None):
    parsed_args = parser.parse_args(args=args)
    logger.setLevel(parsed_args.log_level)
    has_attrs = (getattr(parsed_args, "sort_by", None) and getattr(parsed_args, "columns", None))
    if has_attrs and parsed_args.sort_by not in parsed_args.columns:
        parsed_args.columns.append(parsed_args.sort_by)
    try:
        result = parsed_args.entry_point(parsed_args)
    except Exception as e:
        if isinstance(e, NoRegionError):
            msg = "The AWS CLI is not configured."
            msg += " Please configure it using instructions at"
            msg += " http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html"
            exit(msg)
        elif logger.level < logging.ERROR:
            raise
        else:
            err_msg = traceback.format_exc()
            try:
                err_log_filename = os.path.join(config.user_config_dir, "error.log")
                with open(err_log_filename, "ab") as fh:
                    print(datetime.datetime.now().isoformat(), file=fh)
                    print(err_msg, file=fh)
                exit("{}: {}. See {} for error details.".format(e.__class__.__name__, e, err_log_filename))
            except Exception:
                print(err_msg, file=sys.stderr)
                exit(os.EX_SOFTWARE)
    if isinstance(result, SystemExit):
        raise result
    elif result is not None:
        if isinstance(result, dict) and "ResponseMetadata" in result:
            del result["ResponseMetadata"]
        print(json.dumps(result, indent=2, default=str)) 
开发者ID:kislyuk,项目名称:aegea,代码行数:35,代码来源:__init__.py

示例3: _endpoint_for_partition

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def _endpoint_for_partition(self, partition, service_name, region_name):
        # Get the service from the partition, or an empty template.
        service_data = partition['services'].get(
            service_name, DEFAULT_SERVICE_DATA)
        # Use the partition endpoint if no region is supplied.
        if region_name is None:
            if 'partitionEndpoint' in service_data:
                region_name = service_data['partitionEndpoint']
            else:
                raise NoRegionError()
        # Attempt to resolve the exact region for this partition.
        if region_name in service_data['endpoints']:
            return self._resolve(
                partition, service_name, service_data, region_name)
        # Check to see if the endpoint provided is valid for the partition.
        if self._region_match(partition, region_name):
            # Use the partition endpoint if set and not regionalized.
            partition_endpoint = service_data.get('partitionEndpoint')
            is_regionalized = service_data.get('isRegionalized', True)
            if partition_endpoint and not is_regionalized:
                LOG.debug('Using partition endpoint for %s, %s: %s',
                          service_name, region_name, partition_endpoint)
                return self._resolve(
                    partition, service_name, service_data, partition_endpoint)
            LOG.debug('Creating a regex based endpoint for %s, %s',
                      service_name, region_name)
            return self._resolve(
                partition, service_name, service_data, region_name) 
开发者ID:skarlekar,项目名称:faces,代码行数:30,代码来源:regions.py

示例4: _setup_sqs

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def _setup_sqs(self, session, account_id, region):
        ''' Setup SQS resources'''
        if region in self.sqs_res[account_id]:
            return self.sqs_res[account_id][region]

        try:
            self.sqs_res[account_id][region] = session.resource('sqs', region_name=region)
            return self.sqs_res[account_id][region]
        except NoRegionError:
            self._logger.error("The specified region '%s' for account %s is invalid.",
                               region, account_id) 
开发者ID:StackStorm-Exchange,项目名称:stackstorm-aws,代码行数:13,代码来源:sqs_sensor.py

示例5: test_get_resource_model_attributes

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def test_get_resource_model_attributes(self):
        try:
            resource = boto3.resource('ec2')
        except NoRegionError:
            # skip for environment that doesn't have boto config like CI
            pass
        else:
            collection = resource.instances.all()
            attributes = get_resource_model_attributes(resource, collection)
            assert attributes
            assert 'instance_id' in attributes
            assert 'image_id' in attributes 
开发者ID:lebinh,项目名称:aq,代码行数:14,代码来源:test_boto_engine.py

示例6: client_with_default_region

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def client_with_default_region(service, default_region = DEFAULT_REGION):
    """
    Return a boto3 client for the named *service* in the *default_region* if no
    region is specified in the default session (via the environment, AWS
    config, or ``boto3.setup_default_session``).
    """
    try:
        return boto3.client(service)
    except NoRegionError:
        return boto3.client(service, region_name = default_region) 
开发者ID:nextstrain,项目名称:cli,代码行数:12,代码来源:aws.py

示例7: test_no_completions_when_cant_create_client

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def test_no_completions_when_cant_create_client(describer_creator):
    client_creator = mock.Mock(spec=index.CachedClientCreator)
    # This is raised when you don't have a region configured via config file
    # env var or manually via a session.
    client_creator.create_client.side_effect = NoRegionError()
    completer = index.ServerSideCompleter(
        client_creator=client_creator,
        describer_creator=describer_creator)

    assert completer.retrieve_candidate_values(
        'ec2', 'foo', 'Bar') == [] 
开发者ID:awslabs,项目名称:aws-shell,代码行数:13,代码来源:test_resources.py

示例8: test_default_session

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def test_default_session(self):
        try:
            SecretCache()
        except NoRegionError:
            pass 
开发者ID:aws,项目名称:aws-secretsmanager-caching-python,代码行数:7,代码来源:test_aws_secretsmanager_caching.py

示例9: main

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def main(self, args=None):
        """

        :param args: List of arguments, with the 'aws' removed.  For example,
            the command "aws s3 list-objects --bucket foo" will have an
            args list of ``['s3', 'list-objects', '--bucket', 'foo']``.

        """
        if args is None:
            args = sys.argv[1:]
        command_table = self._get_command_table()
        parser = self._create_parser(command_table)
        self._add_aliases(command_table, parser)
        parsed_args, remaining = parser.parse_known_args(args)
        try:
            # Because _handle_top_level_args emits events, it's possible
            # that exceptions can be raised, which should have the same
            # general exception handling logic as calling into the
            # command table.  This is why it's in the try/except clause.
            self._handle_top_level_args(parsed_args)
            self._emit_session_event(parsed_args)
            HISTORY_RECORDER.record(
                'CLI_VERSION', self.session.user_agent(), 'CLI')
            HISTORY_RECORDER.record('CLI_ARGUMENTS', args, 'CLI')
            return command_table[parsed_args.command](remaining, parsed_args)
        except UnknownArgumentError as e:
            sys.stderr.write("usage: %s\n" % USAGE)
            sys.stderr.write(str(e))
            sys.stderr.write("\n")
            return 255
        except NoRegionError as e:
            msg = ('%s You can also configure your region by running '
                   '"aws configure".' % e)
            self._show_error(msg)
            return 255
        except NoCredentialsError as e:
            msg = ('%s. You can configure credentials by running '
                   '"aws configure".' % e)
            self._show_error(msg)
            return 255
        except KeyboardInterrupt:
            # Shell standard for signals that terminate
            # the process is to return 128 + signum, in this case
            # SIGINT=2, so we'll have an RC of 130.
            sys.stdout.write("\n")
            return 128 + signal.SIGINT
        except Exception as e:
            LOG.debug("Exception caught in main()", exc_info=True)
            LOG.debug("Exiting with rc 255")
            write_exception(e, outfile=get_stderr_text_writer())
            return 255 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:53,代码来源:clidriver.py

示例10: check_metastore_cache_use_encrypt

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import NoRegionError [as 别名]
def check_metastore_cache_use_encrypt(metastore, table_name, log_capture):
    try:
        table = boto3.resource("dynamodb").Table(table_name)
    except NoRegionError:
        table = boto3.resource("dynamodb", region_name=TEST_REGION_NAME).Table(table_name)

    most_recent_provider = MostRecentProvider(provider_store=metastore, material_name="test", version_ttl=600.0)
    e_table = EncryptedTable(table=table, materials_provider=most_recent_provider)

    item = diverse_item()
    item.update(TEST_KEY)
    e_table.put_item(Item=item)
    e_table.put_item(Item=item)
    e_table.put_item(Item=item)
    e_table.put_item(Item=item)

    try:
        primary_puts = _count_puts(log_capture.records, e_table.name)
        metastore_puts = _count_puts(log_capture.records, metastore._table.name)

        assert primary_puts == 4
        assert metastore_puts == 1

        e_table.get_item(Key=TEST_KEY)
        e_table.get_item(Key=TEST_KEY)
        e_table.get_item(Key=TEST_KEY)

        primary_gets = _count_gets(log_capture.records, e_table.name)
        metastore_gets = _count_gets(log_capture.records, metastore._table.name)
        metastore_puts = _count_puts(log_capture.records, metastore._table.name)

        assert primary_gets == 3
        assert metastore_gets == 0
        assert metastore_puts == 1

        most_recent_provider.refresh()

        e_table.get_item(Key=TEST_KEY)
        e_table.get_item(Key=TEST_KEY)
        e_table.get_item(Key=TEST_KEY)

        primary_gets = _count_gets(log_capture.records, e_table.name)
        metastore_gets = _count_gets(log_capture.records, metastore._table.name)

        assert primary_gets == 6
        assert metastore_gets == 1

    finally:
        e_table.delete_item(Key=TEST_KEY) 
开发者ID:aws,项目名称:aws-dynamodb-encryption-python,代码行数:51,代码来源:functional_test_utils.py


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