问题描述
使用 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 started")
(使用 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 set debug on
并没有真正的帮助,我看到的唯一信息是
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,但不是 3,我还从 安装了 pyst3
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配置asterisk
,或者如何找到根本原因?有机会获得有关脚本实际失败位置的更详细日志信息_
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:
- 卸载
pyst3
和 - 强制重新安装
pyst2
,例如pip3 install --upgrade --force-reinstall pyst2
.一开始不知道出了什么问题.
- uninstalled
pyst3
and - forced a re-install of
pyst2
likepip3 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 中使用星号 AGI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!