问题描述
设备向服务端提交一个request请求时发生错误:Invalid response
服务端已经做出正常的反馈了
在提交另一个request请求时是正常的,这两个请求的后端返回数据格式是封装好的同一个类型,只是数据内容不一样。
复现步骤
1.错误请求示例:
设备端代码:
try:
headers={
'ai-token':'*******************************'
}
response = urequests.post(url="http://192.168.28.220:8080/aiApi/text2text?question=whoareyou",headers=headers)
print("状态码:", response.status_code)
print("状态码:", response.text)
response.close()
except Exception as e:
print("错误:", e)
设备端信息反馈:
错误: Invalid response
服务端代码:
@PostMapping("text2text")
public HnResult text2text(@RequestParam("question") String question) {
log.info("文生文");
String answer = text2TextService.talk(question);
log.info(answer);
return HnResult.ok().setData(answer);
}
服务端日志信息:
2025-10-17T18:32:06.297+08:00 INFO 11004 --- [AiManagement] [nio-8080-exec-9] c.e.a.controller.AiApiController : Hello! I'm Qwen, a large-scale language model independently developed by the Tongyi Lab under Alibaba Group. I can assist you with answering questions, writing, logical reasoning, programming, and more. I'm here to help—feel free to ask me anything!
响应内容:{"code":200,"msg":"success","data":"Hello! I'm Qwen, a large-scale language model independently developed by the Tongyi Lab under Alibaba Group. I can assist you with answering questions, writing, logical reasoning, programming, and more. I'm here to helpâfeel free to ask me anything!"}
2.正常请求示例:
设备端代码:
try:
data={
'username':'admin',
'password':'adminadmin'
}
response = urequests.post(url="http://192.168.28.220:8080/user/login",json=data)
print("状态码:", response.status_code)
print("状态码:", response.text)
response.close()
except Exception as e:
print("错误:", e)
设备端信息反馈:
状态码: 200
状态码: {"code":200,"msg":"1977050041946017792","data":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwiaWF0IjoxNzYwNjk3OTQxLCJleHAiOjE3NjA3MTIzNDEsInVzZXJOYW1lIjoiYWRtaW4ifQ.D2kDmdQGnyXx0A6cyjVSJUh8ecNQN8pswwxNMyaph8o"}
服务端代码:
@PostMapping("login")
public HnResult doLogin(@RequestBody LoginReuqest request) {
try {
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(request.getUsername(), request.getPassword());
Authentication authentication = authenticationManager.authenticate(auth);
SecurityContextHolder.getContext().setAuthentication(authentication);
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
User user = (User) userDetails;
if (user.getState()) {
String jwtToken = jwtUtil.getToken(userDetails.getUsername());
return HnResult.ok(user.getUserId()).setData(jwtToken);
} else {
return HnResult.error("登录失败").setData("账号已被锁定");
}
} catch (Exception e) {
log.error(e.getMessage());
log.error("userName or password is not correct");
return HnResult.error("登录失败");
}
}
硬件板卡
庐山派K230
软件版本
CanMV_K230_V3P0_micropython_v1.4-0-g6cce59c_nncase_v2.9.0.img.gz