{"record":{"id":"182d2c1d126e9c96","repo":"babysor/MockingBird","slug":"emotion-enhance-failed-status-resp-status-code","errorCode":null,"errorMessage":"/emotion-enhance failed: status={resp.status_code}, body={resp.text}","messagePattern":"/emotion-enhance failed: status=(.+?), body=(.+?)","errorType":"http","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/speak/scripts/noiz_tts.py","lineNumber":44,"sourceCode":"        canonical = base64.b64encode(decoded).decode(\"ascii\").rstrip(\"=\")\n        if decoded and canonical == key.rstrip(\"=\"):\n            return key\n    except binascii.Error:\n        pass\n    return base64.b64encode(key.encode(\"utf-8\")).decode(\"ascii\")\n\n\ndef call_emotion_enhance(\n    base_url: str, api_key: str, text: str, timeout: int\n) -> str:\n    resp = requests.post(\n        f\"{base_url.rstrip('/')}/emotion-enhance\",\n        headers={\"Authorization\": api_key, \"Content-Type\": \"application/json\"},\n        json={\"text\": text},\n        timeout=timeout,\n    )\n    if resp.status_code != 200:\n        raise RuntimeError(\n            f\"/emotion-enhance failed: status={resp.status_code}, body={resp.text}\"\n        )\n    enhanced = resp.json().get(\"data\", {}).get(\"emotion_enhance\")\n    if not enhanced:\n        raise RuntimeError(f\"/emotion-enhance returned no data: {resp.text}\")\n    return enhanced\n\n\ndef synthesize(\n    base_url: str,\n    api_key: str,\n    text: str,\n    voice_id: Optional[str],\n    reference_audio: Optional[Path],\n    output_format: str,\n    speed: float,\n    emo: Optional[str],\n    target_lang: Optional[str],","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/babysor/MockingBird/blob/28dc5e14f12d7c754612af2fde8e78a4b03f8616/skills/speak/scripts/noiz_tts.py#L26-L62","documentation":"Raised by call_emotion_enhance in noiz_tts.py when the Noiz TTS /emotion-enhance HTTP endpoint returns a non-200 status. This is a remote API failure: the request reached the server but was rejected (auth, bad request, or server error). The response body is included to identify the cause.","triggerScenarios":"POST {base_url}/emotion-enhance with Authorization header and json={\"text\": ...} returns 401/403 (bad API key), 404 (wrong base_url), 400 (empty/oversized text), or 5xx (server overload).","commonSituations":"Wrong or expired NOIZ_API_KEY, base_url pointing at the wrong host/path, network proxy returning 4xx/5xx, or the service being temporarily down.","solutions":["Check the status code and body in the message: 401/403 → fix API key, 404 → fix base_url","Verify base_url matches the documented Noiz API host and has no trailing path mistakes","Retry with backoff for 5xx/429 responses","If body mentions text limits, shorten or sanitize the input text"],"exampleFix":"# before\nresp = requests.post(url, headers={\"Authorization\": api_key}, json={\"text\": text}, timeout=timeout)\n# after (retry transient failures)\nfor attempt in range(3):\n    resp = requests.post(url, headers={\"Authorization\": api_key}, json={\"text\": text}, timeout=timeout)\n    if resp.status_code < 500:\n        break\n    time.sleep(2 ** attempt)","handlingStrategy":"retry","validationCode":"import requests\ndef check_noiz_service(base_url, api_key, timeout=10):\n    r = requests.get(f\"{base_url.rstrip('/')}/health\", headers={\"Authorization\": api_key}, timeout=timeout)\n    return r.status_code == 200","typeGuard":null,"tryCatchPattern":"try:\n    enhanced = call_emotion_enhance(base_url, key, text, timeout)\nexcept RuntimeError as e:\n    if 'status=5' in str(e) or 'status=429' in str(e):\n        time.sleep(2); enhanced = call_emotion_enhance(base_url, key, text, timeout)\n    else:\n        raise","preventionTips":["Validate API key and base_url at startup","Wrap calls in retry-with-backoff for 5xx/429","Log resp.text on failure for diagnosis"],"tags":["http","api","noiz-tts","emotion-enhance"],"backgroundTag":"http-api-error-response","analyzedSha":"28dc5e14f12d7c754612af2fde8e78a4b03f8616","analyzedAt":"2026-08-27T02:26:53.589Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}