From b2106848fb9bf5c92d7cc69e3badb9dc0e8d6d43 Mon Sep 17 00:00:00 2001 From: viveka76 Date: Sun, 21 Jun 2026 21:34:40 +0000 Subject: [PATCH 1/4] Improve NoRegionError message with guidance on setting a region --- .changes/next-release/enhancement-Endpoints-18366.json | 5 +++++ botocore/exceptions.py | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changes/next-release/enhancement-Endpoints-18366.json diff --git a/.changes/next-release/enhancement-Endpoints-18366.json b/.changes/next-release/enhancement-Endpoints-18366.json new file mode 100644 index 0000000000..224c76fb35 --- /dev/null +++ b/.changes/next-release/enhancement-Endpoints-18366.json @@ -0,0 +1,5 @@ +{ + "type": "enhancement", + "category": "Endpoints", + "description": "Improve the NoRegionError message to explain how to set a region (region_name, AWS_DEFAULT_REGION, or ~/.aws/config)." +} diff --git a/botocore/exceptions.py b/botocore/exceptions.py index 294bbf4020..14fb4300b2 100644 --- a/botocore/exceptions.py +++ b/botocore/exceptions.py @@ -243,7 +243,12 @@ class BaseEndpointResolverError(BotoCoreError): class NoRegionError(BaseEndpointResolverError): """No region was specified.""" - fmt = 'You must specify a region.' + fmt = ( + 'You must specify a region. Set it via the region_name argument ' + 'to the client/Session, the AWS_DEFAULT_REGION environment ' + 'variable, or "region" in ~/.aws/config (note: region goes in ' + '~/.aws/config, not ~/.aws/credentials).' + ) class EndpointVariantError(BaseEndpointResolverError): From 1621af6ce3cca939661fbdd1f920b2c3b9bad8ce Mon Sep 17 00:00:00 2001 From: viveka76 Date: Sun, 21 Jun 2026 22:02:37 +0000 Subject: [PATCH 2/4] added tests --- tests/unit/test_regions.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/test_regions.py b/tests/unit/test_regions.py index b4763dd4be..6e637d0b2f 100644 --- a/tests/unit/test_regions.py +++ b/tests/unit/test_regions.py @@ -212,6 +212,9 @@ def test_ensures_region_is_not_none(self): with self.assertRaises(NoRegionError): resolver = regions.EndpointResolver(self._template()) resolver.construct_endpoint('foo', None) + message = str(ctx.exception) + self.assertIn('You must specify a region', message) + self.assertIn('AWS_DEFAULT_REGION', message) def test_ensures_required_keys_present(self): with self.assertRaises(ValueError): From ddd982488ad67d694f1bab5584f879eb644224e7 Mon Sep 17 00:00:00 2001 From: VIVEK SHAW <35144179+viveka76@users.noreply.github.com> Date: Wed, 1 Jul 2026 22:47:27 +0530 Subject: [PATCH 3/4] Apply suggestion from @SamRemis Correct error message Co-authored-by: SamRemis --- botocore/exceptions.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/botocore/exceptions.py b/botocore/exceptions.py index 14fb4300b2..fee4a968f9 100644 --- a/botocore/exceptions.py +++ b/botocore/exceptions.py @@ -244,10 +244,9 @@ class NoRegionError(BaseEndpointResolverError): """No region was specified.""" fmt = ( - 'You must specify a region. Set it via the region_name argument ' - 'to the client/Session, the AWS_DEFAULT_REGION environment ' - 'variable, or "region" in ~/.aws/config (note: region goes in ' - '~/.aws/config, not ~/.aws/credentials).' + 'You must specify a region. This can be done by passing the region_name ' + 'argument to the client or session, using the AWS_DEFAULT_REGION ' + 'environment variable, or setting "region" in the aws config file.' ) From d9fc0187e2e1f1179b2c5f90fb46e03ad3b71734 Mon Sep 17 00:00:00 2001 From: VIVEK SHAW <35144179+viveka76@users.noreply.github.com> Date: Wed, 1 Jul 2026 22:50:39 +0530 Subject: [PATCH 4/4] Update tests/unit/test_regions.py unit tests not needed Co-authored-by: SamRemis --- tests/unit/test_regions.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/test_regions.py b/tests/unit/test_regions.py index 6e637d0b2f..b4763dd4be 100644 --- a/tests/unit/test_regions.py +++ b/tests/unit/test_regions.py @@ -212,9 +212,6 @@ def test_ensures_region_is_not_none(self): with self.assertRaises(NoRegionError): resolver = regions.EndpointResolver(self._template()) resolver.construct_endpoint('foo', None) - message = str(ctx.exception) - self.assertIn('You must specify a region', message) - self.assertIn('AWS_DEFAULT_REGION', message) def test_ensures_required_keys_present(self): with self.assertRaises(ValueError):