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

Go直接调用1Password CLI(op)失败,经Python中转可正常运行的问题求助

Go调用1Password CLI异常问题

问题背景

尝试编写Go程序直接调用1Password CLI工具op执行item list命令,但持续报错;但用Python执行相同命令、或Go通过调用Python脚本间接执行op命令,均能正常运行。

代码与错误详情

初始Go代码(调用失败)

package main

import (
    "fmt"
    "log"
    "os/exec"
)

func main() {
    op := exec.Command("op", "item", "list")
    out, err := op.Output()
    if e, ok := err.(*exec.ExitError); ok {
        log.Fatal(e, ": ", string(e.Stderr))
    }
    fmt.Println(string(out))
}

报错信息

2023/04/13 09:48:51 exit status 1: [ERROR] 2023/04/13 09:48:51 error initializing client: connecting to desktop app: read: connection reset, make sure the CLI is correctly installed and Connect with 1Password CLI is enabled in the 1Password app

正常运行的Python代码

#!/usr/bin/env python

import subprocess

subprocess.run(["op", "item", "list"])

间接调用的Go代码(可正常运行)

package main

import (
    "fmt"
    "log"
    "os/exec"
)

func main() {
    op := exec.Command("/usr/bin/python3.11", "./op.py")
    //op := exec.Command("op", "item", "list")
    out, err := op.Output()
    if e, ok := err.(*exec.ExitError); ok {
        log.Fatal(e, ": ", string(e.Stderr))
    }
    fmt.Println(string(out))
}

测试结果总结

  • Go直接调用op:失败,报连接重置错误
  • Python直接调用op:成功,正常输出结果
  • Go调用Python脚本间接执行op:成功,正常输出结果

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 10:33:35