"C:\Users\WXF\Application Data\Scripts\python.exe" C:\20\frames\n.py No Python at 'D:\BaiduNetdiskDownload\pyhon3.9.0\python.exe' Process finished with exit code 103
时间: 2023-06-25 18:06:58 浏览: 183
这个错误提示意味着你的 Python 解释器路径设置出现了问题。在你的代码中,Python 解释器路径应该是 "C:\Users\WXF\Application Data\Scripts\python.exe",但错误信息中显示的路径是 "D:\BaiduNetdiskDownload\pyhon3.9.0\python.exe",这两个路径不一致。
你可以尝试修改你的代码,将 Python 解释器路径修改为正确的路径 "C:\Users\WXF\Application Data\Scripts\python.exe"。
另外,如果你安装了多个版本的 Python,需要确认你在使用的是正确的 Python 解释器。你可以通过在命令行中执行 "where python" 命令来确认当前使用的 Python 解释器路径。
相关问题
如何将 Python 解释器路径修改为正确的路径 "C:\Users\WXF\Application Data\Scripts\python.exe"。,命令行在哪里
在 Windows 操作系统中,可以通过以下步骤将 Python 解释器路径修改为正确的路径 "C:\Users\WXF\Application Data\Scripts\python.exe":
1. 打开命令提示符(cmd)窗口;
2. 输入命令 `setx path "%path%;C:\Users\WXF\Application Data\Scripts"`。这个命令将会把路径添加到环境变量中;
3. 退出cmd窗口。
现在,你可以重新打开一个cmd窗口,输入`python`,应该会使用正确的Python解释器。
错误: https://qyapi.weixin.qq.com/cgi-bin/gettoken": 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
### 关于PKIX Path Building Failed问题的解决方案
当遇到`PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path for requested target`错误时,通常是因为Java环境无法验证目标服务器的SSL证书链。以下是针对此问题的具体分析和解决方法。
#### 错误的根本原因
该错误的核心在于JDK的信任库(truststore)中缺少目标站点的有效CA证书[^1]。具体来说:
- **HTTPS请求**需要通过SSL/TLS协议建立安全连接。
- Java会尝试验证目标站点的SSL证书是否由受信任的CA签发。
- 如果JDK的信任库中未包含对应的根证书,则会发生`PKIX path building failed`错误。
---
### 解决方案一:导入目标站点的SSL证书到JDK信任库
可以通过手动将目标站点的SSL证书导入到JDK的信任库来解决问题:
1. 访问目标URL `https://qyapi.weixin.qq.com/cgi-bin/gettoken` 并导出其SSL证书。
- 使用浏览器访问页面并查看证书详情,将其保存为`.cer`文件。
2. 将证书导入到JDK的信任库中。
- 定位到JDK安装目录下的`\jre\lib\security\cacerts`文件。
- 打开命令行工具,执行以下命令:
```bash
keytool -import -alias wechat_cert -keystore cacerts -file certificate.cer
```
默认密码为`changeit`[^3]。
3. 验证证书已成功导入。
- 可以通过以下命令检查信任库中的证书列表:
```bash
keytool -list -v -keystore cacerts | grep Alias
```
完成以上操作后,重新运行程序即可正常发起HTTPS请求。
---
### 解决方案二:禁用SSL证书校验(不推荐用于生产环境)
对于开发测试阶段,可以临时关闭SSL证书校验功能。需要注意的是,这种方法存在安全隐患,仅适用于调试场景。
实现方式如下:
```java
package cn.com.webservice.WeChat;
import javax.net.ssl.*;
import java.security.cert.X509Certificate;
import cn.com.webservice.util.HttpRequestUtil;
public class AccessTokenTest {
public static void main(String[] args) throws Exception{
disableSSLCertificateValidation(); // 调用方法禁用SSL校验
String corpid = "wxf9291cddfe5";
String corpsecret = "InWpADosVs7RXG5MwBl8TSTsZ0khvzSK2LQ0";
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
String param = "corpid=" + corpid + "&corpsecret=" + corpsecret;
String result = HttpRequestUtil.sendGet(url, param);
System.out.println(result);
}
private static void disableSSLCertificateValidation() {
try {
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() { return null; }
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
}};
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HostnameVerifier allHostsValid = (hostname, session) -> true;
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
```
上述代码实现了对SSL握手过程的完全绕过[^4]。
---
### 解决方案三:配置Gradle镜像源
如果问题是由于依赖下载失败引起的,可以考虑更换国内镜像源。例如,在项目的`build.gradle`文件中添加阿里云镜像地址:
```groovy
buildscript {
repositories {
google()
jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
}
```
这有助于减少因网络不稳定而导致的证书验证失败问题[^3]。
---
### 总结
- 推荐优先采用**解决方案一**,即手动导入目标站点的SSL证书至JDK信任库。
- 若仅为快速排查问题,可暂时使用**解决方案二**,但在实际部署环境中应避免这种方式。
- 对于依赖管理相关的问题,建议按照**解决方案三**调整Gradle配置。
---
阅读全文
相关推荐













