报错信息:JSON parse error: Unrecognized token ... org.springframework.util.StreamUtils$NonClosingInputSt
·
我在进行pytest框架写自动化测试的时候出现了下面问题
pytest框架报错信息总是显示如下信息时👇
2025-06-24 10:19:53,444 - api_test - DEBUG - 响应内容: {'msg': "JSON parse error: Unrecognized token 'id': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'id': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 4]", 'code': 500}
查了之后发现定位问题时
通常问题出现在你的接口语句上
response = api_client.send_request(method, api_url, params=params, json=data)
你看出这里面的错误了吗??
修改问题?
-
问题根源:
-
使用
data=data发送请求时,默认是application/x-www-form-urlencoded格式 -
服务端期望的是
application/json格式 -
您发送的数据实际是:
id=123&type=4(表单格式) -
服务端收到的是:
id=123&type=4(非 JSON 格式)
-
-
解决方案:
-
使用
json=data参数:-
自动设置
Content-Type: application/json -
自动将字典转换为 JSON 格式
-
-
发送的数据变为:
{"idss": xxx, "tape": 4}(JSON 格式)
-
更多推荐




所有评论(0)