<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">hello Tomi,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"> </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">yeah , when i test, I</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">1) put #!/usr/bin/python3 in the script, or</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">2) run "python3" for the interactive session</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"> yes, just read the <a href="https://github.com/OpenSIPS/opensips/blob/master/modules/python/Makefile" style="font-family:Arial,Helvetica,sans-serif" target="_blank">https://github.com/OpenSIPS/opensips/blob/master/modules/python/Makefile</a> and yeah, it's an ugly hack to have the system run python3 when python is referred to.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"> I had considered removing python 2.7 to which, after searching, it was not a good idea for it would break the system. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">As a quick work around, I went to the modules/python/Makefile and made the following change:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">-PYTHON=python3<br>+PYTHON=/usr/bin/python3<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">Compiled just fine.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">Ran opensips with my config and I got more errors with my regexp which tests out fine on python3's interactive terminal.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">The regexp is in "<span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"> rnRegExp = rnRegExp = re.compile(r'.*rn=\+6114(\d{2})');"</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">Got more error messages:</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">May 18 11:07:41 [58953] ERROR:python:python_handle_exception: python_exec("get_rn"): Unhandled exception in the Python code:<br>May 18 11:07:41 [58953] ERROR:python:python_handle_exception:   TypeError: an integer is required (got type str)<br>May 18 11:07:41 [58953] ERROR:python:python_handle_exception:<br>The above exception was the direct cause of the following exception:<br><br>May 18 11:07:41 [58953] ERROR:python:python_handle_exception:   Traceback (most recent call last):<br>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<br>    return re.match(r'.*rn=\+6114(\d{2})', str(raw_enum_result) ).group(1);<br>May 18 11:07:41 [58953] ERROR:python:python_handle_exception:   SystemError: <class 'str'> returned a result with an error set   <--<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">I found out why.....</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"> I took of the regexp and only issued a 'return "Hello World"' in my function,get_rn().</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"> I kept getting the error, "</span><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">TypeError: an integer is required (got type str)".</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"> </span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">Looked at </span><a href="https://github.com/OpenSIPS/opensips/blob/master/modules/python/python_exec.c#L40-L41" style="font-family:Arial,Helvetica,sans-serif" target="_blank">https://github.com/OpenSIPS/opensips/blob/master/modules/python/python_exec.c#L40-L41</a> and it seems python_exec() will only ever return integers.<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">Thus, that's why it was barfing when I return non integer types.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)">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() (<a href="https://opensips.org/html/docs/modules/1.5.x/perl.html#id293498" style="font-family:Arial,Helvetica,sans-serif" target="_blank">https://opensips.org/html/docs/modules/1.5.x/perl.html#id293498</a>).</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">So, guys, with this discovery, how do we run a python function  and return its output to opensips config??</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,153)"></div></div>