如何在 python3 中使用 Asterisk AGI?

How to use Asterisk AGI with python3?

使用 Asterisk 16.2.1 我的 AGI 脚本(在底部)适用于 python2 #!/usr/bin/env python2,但不适用于 python3 #!/usr/bin/env python3

我什至没有达到 agi.verbose("python agi started")(python3),所以我认为它与 AGI 导入或初始化有关 agi = AGI()

用过agi set debug on并没有多大帮助,我看到的唯一信息是

Launched AGI Script /home/.../asteriskAgi.py
    -- <SIP/..-00000002>AGI Script /home/.../asteriskAgi.py completed, returning 0

因为它适用于 python2,但不适用于 3 我还从 https://pypi.org/project/pyst3/ 安装了 pyst3,但它没有帮助(无论是否使用 [=20,它都不起作用=]已安装)。

问: 知道如何为 python3 配置 asterisk 或如何找到根本原因吗? 任何机会获得有关脚本实际失败位置的更详细的日志信息_

#!/usr/bin/env python3

import sys
import rpyc

from asterisk.agi import AGI

agi = AGI()
agi.verbose("python agi started")
aCallerId = agi.env['agi_callerid']
aType = agi.env["agi_type"]
agi.verbose("XXXXXXXXXXXXXX call from %s" % aCallerId)
agi.verbose(sys.executable)

l = [aCallerId, aType]
agi.verbose("XXXXXXXXXXXXXX l")

c = rpyc.connect("localhost", 18861)
c.root.asteriskCall(l)

即使是这个简约版本也不适用于“3”

#!/usr/bin/env python3

import rpyc

from asterisk.agi import AGI

agi = AGI()
agi.verbose("python agi started")

最终解决了:

  1. 已卸载 pyst3
  2. 强制重新安装 pyst2,如 pip3 install --upgrade --force-reinstall pyst2。一开始不知道哪里出了问题。

你的简约版本适合我(通过 pip 安装了 pyst2)

检查权限和安装的包。还要确保你的星号 运行 在能够找到 python3 和安装包的环境下。