[OpenSIPS-Users] python module - python_exec() behaviour in opensips
Gordon Yeong
anexiole at gmail.com
Fri May 15 22:44:32 EST 2020
It's passed the init. If i did a print (LM_ERR) In the first line of
init(), it doesn't show that print.
If i did a print (LM_ERR)a static string in the get_rn() before the
line that calls compile(), i noticed that it does print out. And if i
tried to print a static string right after the compile() call, it doesn't
print and it calls TypeError.
That's why i suspect something is wrong bit can't tell exactly what....
On Fri, 15 May 2020, 11:21 pm Ben Newlin, <Ben.Newlin at genesys.com> wrote:
> Gordon,
>
>
>
> Are you sure the TypeError is not occurring in mod_init? It looks like you
> are trying to do a print on a Class definition.
>
>
>
> Ben Newlin
>
>
>
> *From: *Users <users-bounces at lists.opensips.org> on behalf of Gordon
> Yeong <anexiole at gmail.com>
> *Reply-To: *OpenSIPS users mailling list <users at lists.opensips.org>
> *Date: *Friday, May 15, 2020 at 1:54 AM
> *To: *OpenSIPS users mailling list <users at lists.opensips.org>
> *Subject: *[OpenSIPS-Users] python module - python_exec() behaviour in
> opensips
>
>
>
> 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
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20200516/1eeec8f7/attachment.html>
More information about the Users
mailing list