You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何向Duckling正确传递JSON参数?解决422错误

问题:Duckling JSON格式请求返回422错误,如何正确传递参数?

在本地8000端口部署Duckling后,使用CURL发送表单格式请求可成功执行:

curl -X POST https://0.0.0.0:8000/parse -d 'locale=en_GB&text=tomorrow at eight'

但发送JSON格式请求时,返回HTTP 422状态码,错误信息为"Need a 'text' parameter to parse":

curl -X POST https://0.0.0.0:8000/parse -H 'Content-Type: application/json' -d '{"locale": "en_GB", "text": "tomorrow at eight"}'

解决方法

1. 适配Shell环境的引号规则

不同Shell对引号的解析逻辑不同,这是JSON参数无法正确传递的常见原因:

  • 类Unix环境(bash/zsh等):保持命令不变,用单引号包裹JSON字符串,避免内部双引号被Shell解析:
    curl -X POST https://0.0.0.0:8000/parse -H 'Content-Type: application/json' -d '{"locale": "en_GB", "text": "tomorrow at eight"}'
    
  • Windows CMD环境:用双引号包裹请求头和JSON字符串,内部双引号需用反斜杠转义:
    curl -X POST https://0.0.0.0:8000/parse -H "Content-Type: application/json" -d "{\"locale\": \"en_GB\", \"text\": \"tomorrow at eight\"}"
    

2. 升级Duckling版本

部分旧版本Duckling未支持JSON格式请求,建议使用官方最新版本启动服务(例如Docker镜像):

docker run -p 8000:8000 rasa/duckling

3. 检查请求协议匹配性

如果Duckling未配置HTTPS,将请求地址中的https替换为http,避免协议不兼容导致参数解析异常:

curl -X POST http://0.0.0.0:8000/parse -H 'Content-Type: application/json' -d '{"locale": "en_GB", "text": "tomorrow at eight"}'

内容的提问来源于stack exchange,提问作者senek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 15:01:11