[OpenSIPS-Users] python module - python_exec() behaviour in opensips

Gordon Yeong anexiole at gmail.com
Mon May 18 01:54:01 EST 2020


hello Tomi,

yeah , when i test, I
1) put #!/usr/bin/python3 in the script, or
2) run "python3" for the interactive session

 yes, just read the
https://github.com/OpenSIPS/opensips/blob/master/modules/python/Makefile and
yeah, it's an ugly hack to have the system run python3 when python is
referred to.
 I had considered removing python 2.7 to which, after searching, it was not
a good idea for it would break the system.

As a quick work around, I went to the modules/python/Makefile and made the
following change:
-PYTHON=python3
+PYTHON=/usr/bin/python3

Compiled just fine.

Ran opensips with my config and I got more errors with my regexp which
tests out fine on python3's interactive terminal.
The regexp is in " rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');"

Got more error messages:

May 18 11:07:41 [58953] ERROR:python:python_handle_exception:
python_exec("get_rn"): Unhandled exception in the Python code:
May 18 11:07:41 [58953] ERROR:python:python_handle_exception:   TypeError:
an integer is required (got type str)
May 18 11:07:41 [58953] ERROR:python:python_handle_exception:
The above exception was the direct cause of the following exception:

May 18 11:07:41 [58953] ERROR:python:python_handle_exception:   Traceback
(most recent call last):
May 18 11:07:41 [58953] ERROR:python:python_handle_exception:     File
"/home/gordon/opensips_proxy_source/modules/python/dumbat.py", line 61, in
get_rn
    return re.match(r'.*rn=\+6114(\d{2})', str(raw_enum_result) ).group(1);
May 18 11:07:41 [58953] ERROR:python:python_handle_exception:
SystemError: <class 'str'> returned a result with an error set   <--




I found out why.....

 I took of the regexp and only issued a 'return "Hello World"' in my
function,get_rn().
 I kept getting the error, "TypeError: an integer is required (got type
str)".

Looked at
https://github.com/OpenSIPS/opensips/blob/master/modules/python/python_exec.c#L40-L41
and
it seems python_exec() will only ever return integers.
Thus, that's why it was barfing when I return non integer types.


I think we really need a function that executes python code and returns
data from the function just like what we have in the perl module,
perl_exec_func() (
https://opensips.org/html/docs/modules/1.5.x/perl.html#id293498).


So, guys, with this discovery, how do we run a python function  and return
its output to opensips config??
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20200518/de45faed/attachment.html>


More information about the Users mailing list