无法找到到请求目标的有效认证路径

问题描述

我正在使用restTemplate进行发布请求,但出现以下错误:无法找到请求目标的有效证书路径

ValueError                                
Traceback (most recent call last) <ipython-input-12-e7a41e4b25cc> in <module>
    ----> 1 births['day']=births['day'].astype(int) ~\anaconda3\lib\site-packages\pandas\core\generic.py in astype(self,dtype,copy,errors)    5696         else:    5697             # else,only a single dtype is given
    -> 5698             new_data = self._data.astype(dtype=dtype,copy=copy,errors=errors)    5699             return self._constructor(new_data).__finalize__(self)    5700  ~\anaconda3\lib\site-packages\pandas\core\internals\managers.py in astype(self,errors)
        580 
        581     def astype(self,copy: bool = False,errors: str = "raise"):
    --> 582         return self.apply("astype",dtype=dtype,errors=errors)
        583 
        584     def convert(self,**kwargs): ~\anaconda3\lib\site-packages\pandas\core\internals\managers.py in apply(self,f,filter,**kwargs)
        440                 applied = b.apply(f,**kwargs)
        441             else:
    --> 442                 applied = getattr(b,f)(**kwargs)
        443             result_blocks = _extend_blocks(applied,result_blocks)
        444  ~\anaconda3\lib\site-packages\pandas\core\internals\blocks.py in astype(self,errors)
        623             vals1d = values.ravel()
        624             try:
    --> 625                 values = astype_nansafe(vals1d,copy=True)
        626             except (ValueError,TypeError):
        627                 # e.g. astype_nansafe can fail on object-dtype of strings ~\anaconda3\lib\site-packages\pandas\core\dtypes\cast.py in astype_nansafe(arr,skipna)
        866 
        867         if not np.isfinite(arr).all():
    --> 868             raise ValueError("Cannot convert non-finite values (NA or inf) to integer")
        869 
        870     elif is_object_dtype(arr): ValueError: Cannot convert non-finite values (NA or inf) to integer

下面是我的方法

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transformToListClass': Invocation of init method Failed; nested exception is java.lang.RuntimeException: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://emploenefitsdev/rion/v1/rion/": sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: java.lang.RuntimeException: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://emploenefitsdev/rion/v1/rion/": sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://emploenefitsdev/rion/v1/rion/": sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

解决方法

在建立从客户端到服务器的https连接时。握手过程失败,因为客户端需要验证服务器证书。在客户端,您需要颁发者证书(Root CA)来验证服务器证书。大多数根证书是JDK中预先存在的。根证书默认情况下存储在称为cacerts的密钥库文件中。在此,服务器证书不是由证书颁发机构颁发的,并且服务器正在使用自签名证书或内部CA颁发的证书。您需要将根CA证书添加到java cacerts密钥存储中。

您可以通过在浏览器中访问服务器站点来轻松检索根CA证书。单击网址栏中的安全锁板,然后浏览证书选项。您需要使用复制选项导出根CA证书,并将证书文件保存在系统上。

转到存在证书的位置eg: C:\Program Files\Java\jdk1.8.0_121\jre\lib\security,然后打开命令提示符以执行以下命令。

keytool -import -alias -aliasName -file pathToRootCA.crt -keystore cacerts

密码为changeit