:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(attio): surface a clear error for a non-ASCII API key (#81668)
Tom Owers8fb4767dcbe2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/attio.py b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/attio.pyindex 0cc740809410..a6ee64230045 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/attio.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/attio.py@@ -124,6 +124,14 @@ def get_resource(name: str) -> EndpointResource:def validate_credentials(api_key: str) -> tuple[bool, str | None]:"""Validate Attio API credentials by making a test request."""+ # A non-ASCII key can't be encoded into the Authorization header (requests uses latin-1),+ # which would otherwise surface a raw UnicodeEncodeError to the user.+ if not api_key.isascii():+ return (+ False,+ "Your Attio API key contains an unsupported character (for example an invisible one pasted "+ "from another app). Retype it by hand and try again.",+ )try:res = make_tracked_session().get("https://api.attio.com/v2/self",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio.py b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio.pynew file mode 100644index 000000000000..9e5da70747cf--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio.py@@ -0,0 +1,14 @@+from products.warehouse_sources.backend.temporal.data_imports.sources.attio.attio import validate_credentials+++class TestValidateCredentials:+ def test_non_ascii_key_returns_actionable_message_without_leaking_encoding_error(self):+ # A non-latin-1 key can't be encoded into the Authorization header; the raw+ # UnicodeEncodeError ("'latin-1' codec can't encode ... ordinal not in range(256)")+ # must never surface to the user.+ valid, msg = validate_credentials("bad中key")++ assert valid is False+ assert "Retype it by hand" in (msg or "")+ assert "latin-1" not in (msg or "")+ assert "ordinal not in range" not in (msg or "")