<div dir="ltr"><div>Hi All,</div><div><br></div><div>I'm using app_python with a KEMI Python routing script. I have been getting occasional Python exception error logs :</div><div><br></div><div><br></div><div><span style="white-space:pre">        </span>kamailio[2242]:  8(2253) ERROR: app_python [python_support.c:150]: python_handle_exception(): python_exec2: Unhandled exception in the Python code:</div><div><span style="white-space:pre">  </span>kamailio[2242]: TypeError: an integer is required</div><div><br></div><div>The scripts seems to function without an issue but these error logs appear fairly frequently, always with an empty Python stack trace.</div><div><br></div><div>I am running Kamailio 5.1 on a Debian 9 system and using Python 2.7 :</div><div><br></div><div><span style="white-space:pre"> </span>>>:/usr/local/etc/kamailio# python --version</div><div><span style="white-space:pre">    </span>Python 2.7.13</div><div><br></div><div><span style="white-space:pre">        </span>>>:/usr/local/etc/kamailio# kamailio -v</div><div><span style="white-space:pre"> </span>version: kamailio 5.1.4 (x86_64/linux) </div><div><span style="white-space:pre">      </span>flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES</div><div>ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB</div><div>poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.</div><div><span style="white-space:pre"> </span>id: unknown </div><div><span style="white-space:pre"> </span>compiled on 18:56:43 Jun  8 2018 with gcc 6.3.0</div><div><br></div><div><br></div><div>I have also tried using a Kamailio load built from the master branch (commit f8b8cecb) which gives enhanced exception logging identifying the function an exception occurs within and parameters. I see this occurring in different parts of the routing script e.g. </div><div><br></div><div>from script</div><div><br></div><div>    def ksr_onsend_route(self,msg):</div><div>        KSR.xlog.xdbg("ONSEND_ROUTE fs=[$fs] $mb\n");</div><div>        return 1;</div><div><br></div><div>an exception is reported within ksr_onsend_route() even when the log level is info.</div><div><br></div><div>Changing log to xlog.xinfo, the log is seen to be sent to syslog but again the exception is reported. These exceptions are always "TypeError: an integer is required" but don't seem related to the Python script.</div><div><br></div><div>Here is an example of the log with a patch applied to to Kamailio 5.1 to show the function the exception is reported within.</div><div><br></div><div><br></div><div><span style="white-space:pre">        </span>kamailio[14092]:  6(14103) ERROR: app_python [python_support.c:156]: python_handle_exception(): apy_exec: ksr_reply_route((null)): Unhandled exception in the Python code:</div><div><span style="white-space:pre">   </span>kamailio[14092]: TypeError: an integer is required</div><div><span style="white-space:pre">    </span>.</div><div><span style="white-space:pre">     </span>.</div><div><span style="white-space:pre">     </span>.</div><div><span style="white-space:pre">     </span>kamailio[14092]: 22(14119) INFO: <script>: ONSEND_ROUTE fs=[udp:<a href="http://10.0.31.126:5080">10.0.31.126:5080</a>] ACK sip:10008@media.test.io:5061;transport=TLS SIP/2.0</div><div><span style="white-space:pre">    </span>.</div><div><span style="white-space:pre">     </span>.</div><div><span style="white-space:pre">     </span>.</div><div><span style="white-space:pre">     </span>.</div><div><span style="white-space:pre">     </span>kamailio[14092]: 22(14119) ERROR: app_python [python_support.c:156]: python_handle_exception(): apy_exec: ksr_onsend_route((null)): Unhandled exception in the Python code:</div><div><span style="white-space:pre">   </span>kamailio[14092]: TypeError: an integer is required</div><div><br></div><div><br></div><div>Has anyone got an idea what can be causing these exceptions and how to avoid them? Currently I have simply patched the load to drop the level of this log to debug when such an exception occurs with an empty traceback as they seem spurious.</div><div><br></div><div>Cheers</div><div>Mike</div><div><br></div></div>