liuxiaoshui
发布于 2023-12-03 / 100 阅读
0
0

记录一次腾讯云人脸模型创建不小心踩的坑

记录一次腾讯云人脸模型创建不小心踩的坑

public void createFaceModel(String name,String driverId,long gender,String photo) throws TencentCloudSDKException {
    // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
    // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
    // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
    Credential cred = new Credential(secretId, secretKey);
    IaiClient client = new IaiClient(cred, region);
    // 实例化一个请求对象,每个接口都会对应一个request对象
    CreatePersonRequest req = new CreatePersonRequest();
    req.setGroupId(groupId);
    req.setPersonName(name);
    req.setPersonId(driverId);
    req.setGender(gender);
    req.setImage(photo);
    req.setUniquePersonControl(uniquePersonControl);
    req.setQualityControl(qualityControl);
    //req.setSkipSign(false);//此处提示
    // 返回的resp是一个CreatePersonResponse的实例,与请求对象对应
    CreatePersonResponse resp = client.CreatePerson(req);
    DriverBusinessResponseEnum.DRIVER_FACE_MODEL_FAIL.assertNotEmpty(resp.getFaceId());
}

调用时,报错:

2023/12/03 10:34:22  ERROR  异常结果:Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.tencentcloudapi.iai.v20200303.models.CreatePersonRequest.setSkipSign(Z)V,{}
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.tencentcloudapi.iai.v20200303.models.CreatePersonRequest.setSkipSign(Z)V
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:517) ~[jakarta.servlet-api-4.0.4.jar:4.0.4]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:584) ~[jakarta.servlet-api-4.0.4.jar:4.0.4]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763) ~[jetty-servlet-9.4.30.v20200611.jar:9.4.30.v20200611]
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1631) ~[jetty-servlet-9.4.30.v20200611.jar:9.4.30.v20200611]
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226) ~[websocket-server-9.4.30.v20200611.jar:9.4.30.v20200611]
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618) ~[jetty-servlet-9.4.30.v20200611.jar:9.4.30.v20200611]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE

就是说找不到setSkipSign方法,其实是CreatePerson()里,调用的

public CreatePersonResponse CreatePerson(CreatePersonRequest req) throws TencentCloudSDKException{
    req.setSkipSign(false);
    return this.internalRequest(req, "CreatePerson", CreatePersonResponse.class);
}

很奇怪,这个类的父类明明有该方法,

public class CreatePersonRequest extends AbstractModel {
	...
	public void setSkipSign(boolean skipSign) {
        this.skipSign = skipSign;
    }
}

换了几次jar包版本,错误依旧。凌乱了

后来从头按接入文档,发现,引入的jar包artifactId不大一样

  		<!--我引入的-->
		<dependency>
            <groupId>com.tencentcloudapi</groupId>
            <artifactId>tencentcloud-sdk-java</artifactId>
            <version>3.1.918</version>
        </dependency>

		<!--官方文档引入的-->
		# 版本在maven生效需要时间,如获取不到对应的版本,可以调低版本号
		<dependency>
		    <groupId>com.tencentcloudapi</groupId>
		    <artifactId>tencentcloud-sdk-java-iai</artifactId>
		    <version>3.1.918</version>
		</dependency>		

后面多了-iai,哎,改成这后好了。

然后找原因,为啥我引入的就会抱这错。

原因:

CreatePersonRequest的父类,AbstractModel,除了在tencentcloud-sdk-java-iai引入包里,还有另一个包tencentcloud-sdk-java-common:3.1.213

也有,但这个类里没有setSkipSign()。这俩全路径名完全相同,而导致运行时,报错了

而引入时,虽然这个包同样引入了,但是判断未冲突了,实际未生效。classpath最终只有这一个正确的AbstractModel。


评论