[OpenSIPS-Users] python module - python_exec() behaviour in opensips
Gordon Yeong
anexiole at gmail.com
Fri May 15 05:53:13 EST 2020
hi guys,
Using opensips 3.0 and python3 here.
I have a script which parses a number in a string (r'.*rn=\+6114(\d{2})').
Script is as follows:
---------- start ---------------
#!/usr/bin/python3
import re;
import pprint;
class test:
def get_rn():
rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');
doit = rnRegExp.match( str("sip:+61386947785;npdi;rn=+
611411 at tipt.ns.zippi.vocus.com;user=phone"));
if doit:
pp = pprint.PrettyPrinter(indent=4);
return doit.group(1);
else:
return None;
result = test.get_rn();
if result is None:
print("Got no match\n");
else:
print("Result is " + result);
----------- end --------------
In my opensips setup, I have the function above looking like this:
---- start--------
from OpenSIPS import LM_ERR
import re;
import pprint;
def mod_init():
print("In mod_init, SIP MSG is : ");
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(SIPMsg);
return SIPMsg();
def __init__():
return 1;
import re;
import pprint;
class SIPMsg:
def child_init(self, rank):
return 0
def get_rn(self, msg, raw_enum_result):
try:
get_rn = re.compile(r'.*rn=\+6114(\d{2})');
rn = get_rn.match(str(raw_enum_result));
return rn.group(1);
except AttributeError:
# Invalid input string
LM_ERR(" attribute ERRor" );
return '';
except TypeError:
# Invalid input string
LM_ERR(" Type Error" );
return '';
else:
LM_ERR(" general ERRor" );
return '';
----- end ------
In my opensips config, I call the get_rn() function via python_exec() as
below.
$var(rn_code)=python_exec("get_rn", $var(raw_string));
I'm facing an issue here because when I run the script by itself in a
command line, it works.
No "Error: Text Type" but when my opensips run, it keeps hitting a
TypeError.
I have even explicitly fed the " rn = get_rn.match(str(raw_enum_result));"
with an explicit string (ie. I dont send use the value passed in from the
argument BUT instead, just feed it an explicit string value) and yet the
same issue occurs.
Does processing control belong directly to python3 when we call
python_exec() or is there something funny going on here?
Thank you
Regards,
Gordon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20200515/5c02b03f/attachment.html>
More information about the Users
mailing list