{"record":{"id":"c2fd0b438a693d4e","repo":"ZhuLinsen/daily_stock_analysis","slug":"alphavantage-api-error-for-symbol-data-erro","errorCode":null,"errorMessage":"[AlphaVantage] API error for {symbol}: {data['Error Message']}","messagePattern":"\\[AlphaVantage\\] API error for (.+?): (.+?)","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"error","filePath":"data_provider/alphavantage_fetcher.py","lineNumber":66,"sourceCode":"        params = {\n            'function': 'TIME_SERIES_DAILY',\n            'symbol': symbol,\n            'outputsize': 'compact',\n            'apikey': self._api_key,\n        }\n\n        try:\n            self.random_sleep(0.5, 1.5)\n            resp = requests.get(_AV_BASE_URL, params=params, timeout=30)\n            resp.raise_for_status()\n            data = resp.json()\n        except Exception as e:\n            raise DataFetchError(f\"[AlphaVantage] HTTP request failed for {symbol}: {e}\") from e\n\n        if 'Note' in data:\n            raise DataFetchError(f\"[AlphaVantage] Rate limited: {data['Note']}\")\n        if 'Error Message' in data:\n            raise DataFetchError(f\"[AlphaVantage] API error for {symbol}: {data['Error Message']}\")\n\n        ts_key = 'Time Series (Daily)'\n        if ts_key not in data or not data[ts_key]:\n            raise DataFetchError(f\"[AlphaVantage] No time series data for {symbol}\")\n\n        rows = []\n        start = datetime.strptime(start_date, '%Y-%m-%d').date()\n        end = datetime.strptime(end_date, '%Y-%m-%d').date()\n        for date_str, values in data[ts_key].items():\n            row_date = datetime.strptime(date_str, '%Y-%m-%d').date()\n            if start <= row_date <= end:\n                rows.append({\n                    'date': date_str,\n                    '1. open': float(values.get('1. open', 0)),\n                    '2. high': float(values.get('2. high', 0)),\n                    '3. low': float(values.get('3. low', 0)),\n                    '4. close': float(values.get('4. close', 0)),\n                    '5. volume': float(values.get('5. volume', 0)),","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/data_provider/alphavantage_fetcher.py#L48-L84","documentation":"A DataFetchError raised by AlphaVantageFetcher._fetch_raw_data when the JSON response contains an 'Error Message' key. AlphaVantage uses this field (with HTTP 200) for hard API-level failures — most commonly an invalid or unknown symbol, but also invalid function parameters or a malformed apikey.","triggerScenarios":"Requesting a symbol AV does not recognize (typo like 'APPL', delisted ticker, or a non-US symbol that slipped past the is_us_stock_code guard); passing an invalid parameter; a truncated/invalid API key that passes the not-empty check but is rejected by the service.","commonSituations":"Watchlists with stale/delisted tickers; symbols with dots or share classes ('BRK.B') that AV rejects; copy-pasted key with whitespace; ADR/OTC tickers unsupported by TIME_SERIES_DAILY.","solutions":["Read the embedded Error Message — AV states the exact reason ('Invalid API call ... symbol').","Validate the symbol exists on AlphaVantage (test with the demo IBM call pattern) before adding it to batch jobs.","Strip whitespace from the API key and re-copy it from the AV dashboard.","Treat as permanent for that symbol: exclude it from AV routing and use a market-appropriate source."],"exampleFix":"# before\nsyms = ['AAPL', 'APPL', 'BRK.B']  # typos/unsupported\nfor s in syms:\n    df = av_fetcher.fetch(s, start, end)  # dies on 'APPL'\n\n# after\nfor s in syms:\n    try:\n        df = av_fetcher.fetch(s, start, end)\n    except DataFetchError as e:\n        if 'API error' in str(e):\n            logger.warning('skip invalid symbol %s: %s', s, e)\n            continue","handlingStrategy":"try-catch","validationCode":"import requests, os\nr = requests.get('https://www.alphavantage.co/query', params={\n    'function': 'TIME_SERIES_DAILY', 'symbol': sym,\n    'apikey': os.environ['ALPHAVANTAGE_API_KEY']}, timeout=10)\ndata = r.json()\nif 'Error Message' in data:\n    raise ValueError(f'symbol {sym} rejected by AlphaVantage: {data[\"Error Message\"]}')","typeGuard":null,"tryCatchPattern":"try:\n    df = av_fetcher.fetch(sym, start, end)\nexcept DataFetchError as e:\n    if 'API error' in str(e):\n        logger.warning('permanently skipping invalid symbol %s: %s', sym, e)\n        continue\n    raise","preventionTips":["Validate symbols against AV once (demo call) before adding them to recurring watchlists.","Strip whitespace/newlines from API keys when configuring them.","Classify 'API error' as permanent-for-symbol: exclude, don't retry."],"tags":["alphavantage","invalid-symbol","api-error","validation"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}