[SR-Users] app_python access to message body content

Anthony Joseph Messina amessina at messinet.com
Sun Aug 7 21:40:52 CEST 2016


On Sunday, August 7, 2016 3:32:32 PM CDT Alex Balashov wrote:
> On 08/07/2016 03:13 PM, Anthony Joseph Messina wrote:
> > I'm trying to play around a bit with app_python using the examples in the
> > source.  I'd like to access the content of the body of the SIP message,
> > but
> > can't figure out how to do that.  I can get headers, method, etc.  How
> > does
> > one access body content with app_python?
> 
> You can pass the appropriate PV ($rb) as the second argument to
> python_exec():
> 
> http://kamailio.org/docs/modules/4.4.x/modules/app_python.html#idp18178284
> 
> In the Python script, you can fish it out with the handler function
> called in the first argument to python_exec(). If you're concerned about
> delimiters and serialisation, you can base64-encode it with
> {s.encode.base64}.
> 
> python_exec() only accepts two arguments, so if you need to pass in more
> data, your best bet is to use the 'jansson' module to construct a JSON
> blob and pass that in as the argument. On the Python side:
> 
>     import json
> 
> 
>     ...
>     class WhateverModule:
>       ...
>       def handler_func(self, msg, args):
>         obj = json.loads(args)
> 
> -- Alex

Thanks Alex.  I guess I was thinking that the whole message would be available 
from within app_python.  This works well.  -A

-- 
Anthony - https://messinet.com/ - https://messinet.com/~amessina/gallery
F9B6 560E 68EA 037D 8C3D  D1C9 FF31 3BDB D9D8 99B6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20160807/6002cd41/attachment.sig>


More information about the sr-users mailing list