Skip to content

Commit

Permalink
fix(python): Fix credential provider error (#21092)
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion authored Feb 5, 2025
1 parent be317eb commit e17f4b2
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions py-polars/polars/io/cloud/credential_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,20 +577,9 @@ def _maybe_init_credential_provider(
# Conservatively warn instead of hard error. It could just be
# set as a default environment flag.
issue_warning(msg, UserWarning)
# Note: Enclosing scope is also within a try-except.
# Note: Enclosing scope will catch ImportErrors
raise

# CredentialProviderAWS raises an error in some cases when
# `get_credentials()` returns None (e.g. the environment may not
# have / require credentials). We check this here and avoid
# auto-initializing it if that is the case.
try:
provider()
except Exception as e:
provider = None
msg = f"error retrieving credentials: {e}"
raise type(e)(msg) from e

elif storage_options is not None and any(
key.lower() not in OBJECT_STORE_CLIENT_OPTIONS for key in storage_options
):
Expand All @@ -600,9 +589,23 @@ def _maybe_init_credential_provider(

except ImportError as e:
if verbose:
msg = f"Unable to auto-select credential provider: {e}"
msg = f"unable to auto-select credential provider: {e!r}"
print(msg, file=sys.stderr)

if provider is not None:
# CredentialProviderAWS raises an error in some cases when
# `get_credentials()` returns None (e.g. the environment may not
# have / require credentials). We check this here and avoid
# using it if that is the case.
try:
provider()
except Exception as e:
provider = None

if verbose:
msg = f"unable to auto-select credential provider: {e!r}"
print(msg, file=sys.stderr)

if provider is not None and verbose:
msg = f"auto-selected credential provider: {type(provider).__name__}"
print(msg, file=sys.stderr)
Expand Down

0 comments on commit e17f4b2

Please sign in to comment.