技术博客
科学计算器错误码排查:ret_code -1、方法调用出错、operation 不能为空

科学计算器错误码排查:ret_code -1、方法调用出错、operation 不能为空

作者: 万维易源
2026-09-03
科学计算器错误码排查
# 科学计算器错误码排查:ret_code -1、方法调用出错、operation 不能为空 > 接口 免费科学计算器(apiCode 1699)· 接入点 科学计算器(1699-1)· 免费 · POST/GET · 返回 JSON · 适合 调试中的开发者 · 阅读约 4 分钟 ## 核心要点 - 业务成败看 `showapi_res_body.ret_code`:`0` 成功、`-1` 失败(不计费)。 - 失败原因在 `remark` 文案里:`operation不能为空或者不正确` 或 `方法调用出错`。 - 多数失败源于「操作名写错 / 参数个数不对 / 用了暂不可用的操作」,而非接口故障。 ## Why:为什么要把错误码讲透 接口报错时不像浏览器那样弹出提示,只给你一个 `remark` 字符串。如果不提前知道每种文案对应什么毛病,排查起来很费时间。本篇把实测遇到的几类错误和对应解法列成对照表,照表对号入座即可。 ## What:接口速览 | 项目 | 说明 | |------|------| | 请求地址 | `https://route.showapi.com/1699-1?appKey={your_appKey}` | | 成功标志 | `ret_code == 0` 且 `result` 非空 | | 计费 | 免费,[使用档次限制](https://www.showapi.com/free-api) | ## How:错误排查对照表 ```python import requests APP_KEY = "YOUR_APPKEY" r = requests.post( "https://route.showapi.com/1699-1", params={"appKey": APP_KEY}, data={"num": "1", "operation": "badop", "rad_or_ang": ""}, timeout=10 ) b = r.json()["showapi_res_body"] print("ret_code:", b.get("ret_code"), "| remark:", b.get("remark")) # ret_code: -1 | remark: operation不能为空或者不正确 ``` ### 实测错误类型对照 | `remark` 文案 | 含义 | 排查方向 | |------|------|---------| | `operation不能为空或者不正确` | `operation` 为空或不在 32 个合法名内 | 核对[操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699),注意全小写 | | `方法调用出错` | 操作名合法但执行失败(如暂不可用的 `subtraction`/`percentage`、参数个数不匹配) | 检查参数个数;避开已知不可用操作(见[已知问题](https://www.showapi.com/guides/calculator-known-issues-1699)) | | 空 `result` + `ret_code -1` | 渠道/方法级失败 | 看 `remark` 文案定位;重试或换个写法 | ## 返回示例与解析 ### 操作名写错 ```json { "showapi_res_body": { "ret_code": -1, "remark": "operation不能为空或者不正确", "result": null } } ``` ### 方法调用出错(如暂不可用的减法) ```json { "showapi_res_body": { "ret_code": -1, "remark": "方法调用出错", "result": null } } ``` > 判定建议:先 `str(ret_code) == "0"` 再读 `result`;非 0 直接读 `remark` 透传给日志/前端。 ## 进阶 / 边界 - **`operation` 名要全小写**:文档与实测均用小写(如 `arccos`),大小写不符会触发「operation不能为空或者不正确」。 - **参数个数不对也会「方法调用出错」**:例如单参数 `sqrt` 退化(不报错但结果不对),而某些组合会直接报「方法调用出错」。 - **网络/超时**:极端情况下 `showapi_res_code` 非 0 或超时,属系统级问题,与业务 `ret_code` 不同层。 ## FAQ **Q1:返回 `result` 是 null 怎么办?** 先看 `ret_code`:非 0 时 `result` 就是空,直接读 `remark` 定原因,不要硬读 `result`。 **Q2:提示「operation不能为空或者不正确」?** `operation` 写错或大小写不对。对照[操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699) 用正确的小写名。 **Q3:提示「方法调用出错」但操作名没错?** 可能是参数个数不匹配,或用了暂不可用的 `subtraction` / `percentage`。详见[已知问题](https://www.showapi.com/guides/calculator-known-issues-1699)。 **Q4:免费接口会限流吗?** 有[使用档次限制](https://www.showapi.com/free-api),异常频繁调用可能触发限制,建议合理控制频率。 **Q5:`showapi_res_code` 和 `ret_code` 都要看吗?** 业务判断看 `ret_code` 即可;`showapi_res_code` 是整次请求的系统状态,正常为 0。 ## 相关能力 / 下一步阅读 - [科学计算器返回字段全解](https://www.showapi.com/guides/calculator-response-fields-1699) —— `ret_code`/`result`/`remark` 字段含义 - [科学计算器已知问题与使用避坑](https://www.showapi.com/guides/calculator-known-issues-1699) —— 暂不可用操作与退化行为 - [科学计算器操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699) —— 合法操作名清单 - **本系列共 11 篇**:查看[科学计算器开发指南总目录](https://www.showapi.com/guides/calculator-guides-1699)