`401 Unauthorized` from an internal API only for requests that follow a redirect.
AdvancedTroubleshootingboto3, HTTP & API errors
Answer
Likely causes → requests strips the Authorization header when redirected to a different host (to avoid leaking credentials), and the redirect target needs auth.
Diagnose →
r = s.get(url, allow_redirects=False); print(r.status_code, r.headers.get("Location"))
Fix → Call the final URL directly, or handle the redirect yourself and re-add auth only if the new host is trusted.
Prevent → Configure clients with canonical endpoints; keep the security behaviour, do not disable it globally.
More on boto3, HTTP & API errors
`botocore.exceptions.NoCredentialsError: Unable to locate credentials`Beginner`botocore.exceptions.NoRegionError: You must specify a region.` even though `AWS_REGION` is set.Intermediate`botocore.exceptions.ClientError: An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.`Beginner`An error occurred (ExpiredToken) when calling the ... operation: The security token included in the request is expired` midway through a long job.Advanced`An error occurred (RequestLimitExceeded) when calling the DescribeInstances operation (reached max retries: 4): Request limit exceeded.`Intermediate`An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid.`Beginner