{"record":{"id":"3e7f3de676268155","repo":"ZhuLinsen/daily_stock_analysis","slug":"tickflow-api-key-is-not-configured","errorCode":null,"errorMessage":"TickFlow API key is not configured","messagePattern":"TickFlow API key is not configured","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"error","filePath":"data_provider/tickflow_fetcher.py","lineNumber":183,"sourceCode":"            if self._client is None:\n                self._client = self._build_client()\n            return self._client\n\n    def _fetch_raw_data(\n        self, stock_code: str, start_date: str, end_date: str\n    ) -> pd.DataFrame:\n        symbol = self._to_tickflow_symbol(stock_code)\n        if not symbol:\n            raise DataFetchError(\"TickFlowFetcher only supports A-share/ETF symbols\")\n\n        cache_key = self._daily_cache_key(symbol, start_date, end_date)\n        cached = self._get_daily_cache(cache_key)\n        if cached is not None:\n            return cached\n\n        client = self._get_client()\n        if client is None:\n            raise DataFetchError(\"TickFlow API key is not configured\")\n\n        request_count = self._daily_kline_count(start_date, end_date)\n        try:\n            df = client.klines.get(\n                symbol,\n                period=\"1d\",\n                count=request_count,\n                start_time=self._date_to_ms(start_date),\n                end_time=self._date_to_ms(end_date, end_of_day=True),\n                adjust=self.kline_adjust,\n                as_dataframe=True,\n            )\n        except Exception as exc:\n            raise DataFetchError(f\"TickFlow daily K-line request failed: {exc}\") from exc\n\n        raw_df = self._prepare_daily_frame(\n            df,\n            symbol=symbol,","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/data_provider/tickflow_fetcher.py#L165-L201","documentation":"DataFetchError raised in TickFlowFetcher._fetch_raw_data when _get_client() returns None, i.e. no TickFlow API key is configured in the environment (the client cannot be built without credentials). It fails after the symbol check and cache lookup but before any request is attempted.","triggerScenarios":"Any daily-K-line fetch via TickFlowFetcher when the TICKFLOW_API_KEY (or equivalent env/config) is absent, empty, or failed validation during _build_client.","commonSituations":"New deployment missing the TickFlow key in .env; key present in a different environment (local vs CI vs Docker); key removed or renamed without updating .env.example and deployment docs.","solutions":["Set the TickFlow API key in the runtime environment (and mirror it in .env.example).","Skip registering TickFlowFetcher in the provider chain when the key is absent, so requests route to keyless providers.","Add a startup credential probe that logs which providers are enabled."],"exampleFix":"# before\ndf = tickflow_fetcher.get_stock_data(\"600519\", start, end)  # DataFetchError: key not configured\n\n# after\n# .env: TICKFLOW_API_KEY=...\nif tickflow_fetcher._get_client() is not None:\n    df = tickflow_fetcher.get_stock_data(\"600519\", start, end)\nelse:\n    df = akshare_fetcher.get_stock_data(\"600519\", start, end)","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"TICKFLOW_API_KEY\"):\n    logger.info(\"TickFlow key absent; provider disabled\")\n    # do not register TickFlowFetcher in the chain","typeGuard":null,"tryCatchPattern":"try:\n    df = tickflow_fetcher.get_stock_data(code, start, end)\nexcept DataFetchError as e:\n    if \"API key is not configured\" in str(e):\n        df = akshare_fetcher.get_stock_data(code, start, end)\n    else:\n        raise","preventionTips":["Register credential-gated providers only when their key is present.","Keep .env.example and deployment docs listing every provider credential.","Log enabled providers at startup to catch missing keys before the first request."],"tags":["tickflow","credentials","configuration","api-key"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}