首页 > 解决方案 > Freeswitch 从拨号计划运行 python 脚本

问题描述

我正在尝试从 freeswitch dialplan 在 python 中运行脚本。该脚本调用了本地 REDIS 数据库,每次来电时我都需要查询该数据库。到目前为止,我能够使用 mod_python 编译 freeswitch,我什至可以像这样从 fs_cli 运行 test.py 脚本:

freeswitch@reverse> python test
2021-06-25 16:36:36.007177 [NOTICE] mod_python.c:213 Invoking py module: test
2021-06-25 16:36:36.027120 [INFO] switch_cpp.cpp:1465 test
Hello

But when  try to add in the test.py the “import redis” line in order to work with my redis db  I’m getting : 

freeswitch@reverse> python test
2021-06-25 16:37:17.847161 [NOTICE] mod_python.c:213 Invoking py module: test
2021-06-25 16:37:17.847161 [ERR] mod_python.c:261 Error reloading module


2021-06-25 16:37:17.847161 [ERR] mod_python.c:165 Python Error by calling script "test": <type 'exceptions.ImportError'>
Message: No module named redis
Exception: None

Traceback (most recent call last)
        File: "/usr/share/freeswitch/scripts/test.py", line 1, in <module>

也许我没有正确使用pythons脚本?..我可以使用调用另一个模块的脚本吗?...可能吗?或者也许有更好的方法来做到这一点?

谢谢!

标签: pythonfreeswitch

解决方案


先安装redis模块

# example for centos
yum install python-redis

推荐阅读