<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">hi guys,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"> Using opensips 3.0 and python3 here.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"> I have a script which parses a number in a string (r'.*rn=\+6114(\d{2})').</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">Script is as follows:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">---------- start ---------------</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">#!/usr/bin/python3<br>import re;<br>import pprint;<br><br><br>class test:<br><br> def get_rn():<br> rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');<br> doit = rnRegExp.match( str("sip:+61386947785;npdi;rn=+<a href="mailto:611411@tipt.ns.zippi.vocus.com">611411@tipt.ns.zippi.vocus.com</a>;user=phone"));<br><br> if doit:<br> pp = pprint.PrettyPrinter(indent=4);<br> return doit.group(1);<br> else:<br> return None;<br><br>result = test.get_rn();<br><br>if result is None:<br> print("Got no match\n");<br>else:<br> print("Result is " + result);<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">----------- end --------------</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">In my opensips setup, I have the function above looking like this:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">---- start--------</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br>from OpenSIPS import LM_ERR<br>import re;<br>import pprint;<br><br>def mod_init():<br> print("In mod_init, SIP MSG is : ");<br> pp = pprint.PrettyPrinter(indent=4)<br> pp.pprint(SIPMsg);<br> return SIPMsg();<br><br>def __init__():<br> return 1;<br><br>import re;<br>import pprint;<br><br>class SIPMsg:<br><br> def child_init(self, rank):<br> return 0<br><br> def get_rn(self, msg, raw_enum_result):<br> try:<br> get_rn = re.compile(r'.*rn=\+6114(\d{2})');<br><br> rn = get_rn.match(str(raw_enum_result));<br> return rn.group(1);<br> except AttributeError:<br> # Invalid input string<br> LM_ERR(" attribute ERRor" );<br> return '';<br> except TypeError:<br> # Invalid input string<br> LM_ERR(" Type Error" );<br> return '';<br> else:<br> LM_ERR(" general ERRor" );<br> return '';<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">----- end ------</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">In my opensips config, I call the get_rn() function via python_exec() as below.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">$var(rn_code)=python_exec("get_rn", $var(raw_string));<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">I'm facing an issue here because when I run the script by itself in a command line, it works.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"> No "Error: Text Type" but when my opensips run, it keeps hitting a TypeError.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"> 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.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">Does processing control belong directly to python3 when we call python_exec() or is there something funny going on here?</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"> </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099">Thank you</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:#000099"><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font color="#000000" face="verdana, sans-serif">Regards,<br>Gordon </font></div></div></div></div></div></div></div></div></div></div></div></div>