本文介绍了如何在python3中使用Asterisk AGI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using Asterisk 16.2.1 my AGI script (at the bottom) works with python2 #!/usr/bin/env python2, but not with python3 #!/usr/bin/env python3.

我什至不了解 agi.verbose("python agi starts")(使用python3),所以我认为它与AGI导入或初始化有关.agi = AGI()

I do not even get as far as agi.verbose("python agi started") (with python3), so I assume it has something to do with the AGI import or initialization agi = AGI()

使用 agi将调试设置为并没有真正的帮助,我看到的唯一信息是

Having used agi set debug on does not really help, the only info I see is

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

由于它可与python2一起使用,但不适用于python2,因此我还从https://pypi.org/project/pyst3/,但是它没有帮助(无论是否安装 pyst3 都不能使用).

As it works with python2, but not 3 I have also installed pyst3 from https://pypi.org/project/pyst3/ , but it did not help (it does not work with or without pyst3 installed).

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

Q: Any idea how to configure asterisk for python3, or how to find the root cause?Any chance to get more detailed log information of where the script actually fails_

#!/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"


Even this minimalistic version does not work with "3"

#!/usr/bin/env python3

import rpyc

from asterisk.agi import AGI

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


最终通过以下方式解决:


eventually solved by:

  1. 未安装的 pyst3
  2. 强制重新安装 pyst2 ,例如 pip3 install --upgrade --force-reinstall pyst2 .首先不知道出了什么问题.
  1. uninstalled pyst3 and
  2. forced a re-install of pyst2 like pip3 install --upgrade --force-reinstall pyst2. No idea what went wrong in the first place.

推荐答案

您的极简版本对我有用(通过pip安装pyst2)

Your minimalistic version works for me(with pyst2 installed via pip)

检查许可权和已安装的软件包.另外,请确保您的星号在能够找到python3和已安装软件包的环境下运行.

Check permission and installed packages. Also ensure that your asterisk running under environment which able find python3 and packages installed.

这篇关于如何在python3中使用Asterisk AGI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 18:47