iflytek/astron-agent · error · ThirdPartyException
Signature generation error
Error message
Signature generation error: {e} What it means
get_signature() wraps the whole SparkDesk signature computation (md5 of appid+ts, then HMAC-SHA1 with api_secret) in a try/except; any failure is logged and re-raised as ThirdPartyException(f"Signature generation error: {e}"). It indicates bad inputs or missing crypto dependencies rather than a remote call.
Solutions
- Verify the appid and api_secret config/env values are present, non-empty strings (strip whitespace)
- Log/inspect the wrapped exception message to identify the failing primitive (md5 vs hmac)
- Add startup validation that raises early if SPARK credentials are missing
Example fix
// before
appid = os.getenv("SPARK_APP_ID") # None
sig = get_signature(appid, secret) # Signature generation error
// after
appid = os.environ["SPARK_APP_ID"].strip()
secret = os.environ["SPARK_API_SECRET"].strip()
if not appid or not secret: raise ConfigError("Spark credentials missing")
sig = get_signature(appid, secret) Defensive patterns
Strategy: try-catch
Validate before calling
def spark_credentials_ok(appid, secret) -> bool:
return bool(appid) and bool(secret) and isinstance(appid, str) and isinstance(secret, str) Type guard
def has_valid_spark_config(cfg: dict) -> bool:
return isinstance(cfg.get("appid"), str) and bool(cfg["appid"].strip()) and isinstance(cfg.get("api_secret"), str) and bool(cfg["api_secret"].strip()) Try / catch
try:
headers = assemble_spark_auth_headers_async(...)
except ThirdPartyException as e:
logger.error(f"Spark auth failed: {e}")
raise CredentialsConfigError("Check SPARK_APP_ID / SPARK_API_SECRET") from e Prevention
- Validate Spark credentials exist and are strings at startup
- Strip whitespace/newlines from copied secrets
- Never pass None config values into signature functions
- Alert on 'Signature generation failed' logs, they almost always mean config issues
When it happens
Trigger: Calling get_signature with appid=None/non-string that fails str concatenation, or api_secret missing/None causing hmac_sha1_encrypt to fail (e.g. invalid key type for hmac.new).
Common situations: Missing or misconfigured SPARK_APP_ID / SPARK_API_SECRET environment variables; secrets loaded as None from config; copy-pasted secret containing whitespace/newlines causing encode failures.
Related errors
- SparkDesk-RAG does not support split operation.
- SparkDesk-RAG does not support chunks_save operation.
- SparkDesk-RAG does not support chunks_update operation.
- SparkDesk-RAG does not support chunks_delete operation.
- SparkDesk-RAG does not support query_doc operation.
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/8204567e6d204007.
Report an issue: GitHub.
Appendix: source
Thrown at core/knowledge/utils/spark_signature.py:27
def get_signature(appid: str, ts: int, api_secret: str) -> str:
"""
Generate API request signature.
Args:
appid: Application ID
ts: Timestamp
api_secret: API secret key
Returns:
Signature string
"""
try:
auth = md5(appid + str(ts))
return hmac_sha1_encrypt(auth, api_secret)
except Exception as e:
logger.error(f"Signature generation failed: {e}")
raise ThirdPartyException(f"Signature generation error: {e}")
def md5(cipher_text: str) -> str:
"""
Generate MD5 hash value.
Args:
cipher_text: Text to be hashed
Returns:
MD5 hash string
"""
try:
data = cipher_text.encode("utf-8")
md = hashlib.md5()
md.update(data)
return md.hexdigest()
except Exception as e:View on GitHub (pinned to 5e758547a8)