{"record":{"id":"3f27614feb9e9c37","repo":"OpenBB-finance/OpenBB","slug":"error-get-code-error-get-message","errorCode":null,"errorMessage":"{error.get('code', '')} -> {error.get('message', '')}","messagePattern":"\\{error\\.get\\('code', ''\\)\\} -> \\{error\\.get\\('message', ''\\)\\}","errorType":"exception","errorClass":"UnauthorizedError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/congress_gov/openbb_congress_gov/models/amendment_info.py","lineNumber":107,"sourceCode":"        from openbb_core.provider.utils.helpers import amake_request\n\n        api_key = credentials.get(\"congress_gov_api_key\", \"\") if credentials else \"\"\n        amendment_url = query.amendment_url\n\n        if amendment_url[0].isnumeric() or (\n            amendment_url[0] == \"/\" and amendment_url[1].isnumeric()\n        ):\n            amendment_url = (\n                \"https://api.congress.gov/v3/amendment/\"\n                + f\"{amendment_url[1:] if amendment_url[0] == '/' else amendment_url}?format=json\"\n            )\n\n        url = amendment_url + \"&api_key=\" + api_key\n        base_info: dict = await amake_request(url)  # type: ignore\n\n        if isinstance(base_info, dict) and (error := base_info.get(\"error\", {})):\n            if \"API_KEY\" in error.get(\"code\", \"\"):\n                raise UnauthorizedError(\n                    f\"{error.get('code', '')} -> {error.get('message', '')}\"\n                )\n            raise OpenBBError(f\"{error.get('code', '')} -> {error.get('message', '')}\")\n\n        base_info = base_info.get(\"amendment\", {})\n\n        cosponsors = base_info.get(\"cosponsors\", {})\n        if isinstance(cosponsors, dict) and cosponsors.get(\"count\", 0) > 0:\n            cosponsors_url = cosponsors.get(\"url\", \"\") + \"&api_key=\" + api_key\n            cosponsors_response: dict = await amake_request(cosponsors_url)  # type: ignore\n            cosponsors_list = cosponsors_response.get(\"cosponsors\", [])\n            if cosponsors_list:\n                base_info[\"cosponsors\"] = cosponsors_list\n\n        actions = base_info.get(\"actions\", {})\n        if actions.get(\"count\", 0) > 0:\n            actions_url = actions.get(\"url\", \"\") + \"&api_key=\" + api_key\n            actions_response: dict = await amake_request(actions_url)  # type: ignore","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/congress_gov/openbb_congress_gov/models/amendment_info.py#L89-L125","documentation":"UnauthorizedError raised by the congress.gov amendment-info fetcher when the API response body contains an error whose code includes 'API_KEY' — i.e. congress.gov rejected the credentials. The message concatenates the upstream code and message (e.g. 'API_KEY_NOT_FOUND -> No API key found...'). OpenBB maps this to an auth failure so callers can distinguish 'bad key' from other API errors.","triggerScenarios":"Calling CongressAmendmentInfo without a congress_gov_api_key credential; a key that was revoked, exceeded its rate limit (over 5,000 requests/hour keys get suspended), or never set in the OpenBB hub credentials; env var name typo like CONGRESS_GOV_APIKEY.","commonSituations":"Fresh installs where the key was never provisioned; CI environments missing the credential secret; shared keys hitting the hourly quota; keys invalidated after the congress.gov key migration.","solutions":["Set the credential: obb.account.credentials.set('congress_gov_api_key', '<key>') or export CONGRESS_GOV_API_KEY.","Verify the key works with a direct curl to https://api.congress.gov/v3/bill?format=json&api_key=<key>.","If rate-limited, wait for the quota window to reset or request a higher tier key from congress.gov."],"exampleFix":"# before\nobb.congress.amendment_info(amendment_url='119/hamdt/2')\n\n# after\nobb.account.credentials.set('congress_gov_api_key', os.environ['CONGRESS_GOV_API_KEY'])\nobb.congress.amendment_info(amendment_url='119/hamdt/2')","handlingStrategy":"validation","validationCode":"import obb\nkey = obb.account.credentials.get('congress_gov_api_key')\nif not key:\n    raise RuntimeError('congress_gov_api_key is not configured')","typeGuard":null,"tryCatchPattern":"from openbb_core.provider.utils.errors import UnauthorizedError\n\ntry:\n    res = obb.congress.amendment_info(amendment_url='119/hamdt/2')\nexcept UnauthorizedError:\n    raise SystemExit('Fix congress_gov_api_key in OpenBB credentials') from None","preventionTips":["Set credentials once per environment via obb.account.credentials.set.","Smoke-test the key with one direct API call in deployment checks.","Stay under 5,000 requests/hour; cache responses to avoid quota-driven suspensions."],"tags":["congress-gov","auth","api-key","credentials","openbb"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}