You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GetProxyPairs报错:找不到tools/proxies.txt文件,请求技术支持

问题排查与解决方案

1. 先暴露真实错误原因(最关键)

你的异常捕获逻辑太宽泛,把所有类型错误都归为「文件不存在」,导致真正的问题被掩盖。先修改代码,打印具体异常信息:

def GetProxyPairs():
    try:
        prox_pair = {}
        # Use the full path to the "tools" directory
        TOOLS_DIR = join(dirname(abspath(__file__)), "tools")
        proxies_file_path = join(TOOLS_DIR, "proxies.txt")
        print("Proxies file path:", proxies_file_path)  # Print the path for debugging
        with open(proxies_file_path, "r") as f:
            proxy_list = f.readlines()
            for i in range(len(proxy_list)):
                proxy_list[i] = proxy_list[i].strip()
                prox_pair[proxy_list[i].split("-")[0]] = proxy_list[i].split("-")[1]
        proxy_list.clear()
    except Exception as e:
        # 打印真实错误信息,定位问题根源
        error_msg = f"Error in GetProxyPairs -> {str(e)}"
        logger.PrintColored(error_msg, "fail")
        print(error_msg)  # 控制台同步输出,确保不遗漏
        return {}
    return prox_pair

运行后就能看到到底是文件不存在、权限不足,还是文件格式错误导致的问题。

2. 针对「路径正确但文件找不到」的常见排查点

- 验证文件实际存在

直接复制打印的路径C:\Users\duczl\OneDrive\Desktop\v2main\modules\tools\proxies.txt到资源管理器地址栏,回车后检查:

  • 如果找不到文件,说明路径实际有误(比如OneDrive同步延迟、文件夹改名)
  • 如果能找到文件,继续排查下面的点

- 检查文件名是否有隐藏后缀

Windows默认隐藏已知文件类型的扩展名,可能你的文件实际是proxies.txt.txt(显示为proxies.txt)。解决方法:

  1. 打开资源管理器,点击「查看」选项卡
  2. 勾选「文件扩展名」
  3. 确认文件名确实是proxies.txt

- 解决OneDrive同步问题

如果文件在OneDrive目录下,可能处于「仅在线」状态(图标为云),脚本无法读取本地文件。解决方法:
右键点击proxies.txt,选择「始终在此设备上保留」,等待同步完成后再运行脚本

- 检查文件权限

当前运行脚本的用户可能没有读取该文件的权限:

  1. 右键proxies.txt → 属性 → 安全
  2. 检查当前用户是否有「读取」权限,没有则添加对应权限

- 测试硬编码路径

暂时把路径写死,排除路径拼接逻辑的问题:

proxies_file_path = r"C:\Users\duczl\OneDrive\Desktop\v2main\modules\tools\proxies.txt"

如果这样能正常读取,说明join(dirname(abspath(__file__)), "tools")的拼接不符合预期(比如脚本被import时,__file__的路径和你预期的不一致)

3. 代码优化建议

  • 遍历列表时无需使用range(len(proxy_list)),直接遍历元素更简洁,同时增加格式校验避免报错:
for line in proxy_list:
    line = line.strip()
    if not line:  # 跳过空行
        continue
    parts = line.split("-")
    if len(parts) == 2:  # 确保每行格式符合"key-value"要求
        prox_pair[parts[0]] = parts[1]
  • 无需手动调用proxy_list.clear(),函数执行结束后列表会自动被回收

内容的提问来源于stack exchange,提问作者Hashin Veselko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 01:24:57