On 09/02/2017 16:47, Konstantin M. wrote:
That's correct, it accepts only one parameter for now.
After many years our company has switched to kamailio, I'm actively working on new version of app_python, more flexible and usable than current one, many new features...
I'm not ready to push new changes to current module due to raw alpha and unstable work.

If you haven't seen it, note the addition of support for kemi in the app_python. That should be preserved.

Right now. as workaround you can pass something like $_s($fu!!$tu) and then in python parse them with from_user, to_user = $param1.split("!!")

Quickly looking in the source code, the function doesn't evaluate the variables in the parameters. I will try to fix it soon.

Cheers,
Daniel


2017-02-09 11:31 GMT+03:00 Daniel-Constantin Mierla <miconda@gmail.com>:
Hello,

not very familiar with the app_python initial design, but when I added
kemi support in it for kamailio 5.0, I think I noticed the limitation of
1 extra parameter. Probably you can encode your parameters in comma
separated value, so you can parse it easier in the python script, as
opposite to parsing the entire message buffer.

An alternative may be getting the value for $fu or $tu if python offers
the api for getting/setting pseudo-variables -- these are for sure in
kemi exports to python.

Of course, if anyone adds support for more parameters, then it will be
accepted inside kamailio repo.

Cheers,
Daniel


On 08/02/2017 09:47, gmele wrote:
> Hello,
>
> in our Kamailio, we are using python_exec to execute script used to send
> push notifications to Google or Apple.
>
> Currenty, the method we call only accepts the message as parameter. We then
> extract from the message the Call Id, to URI and from URI.
>
> Here is the python method signature:
>
> *def SendPushNotification(self, msg)*
>
> To extract the toUri and fromUri (and remove the sip:), we use python regex
> :
>
> *uriPattern=re.compile(".*sips?:(.+@[^>;]+)")*
>
> This is working well 99% of the time, except sometimes (we don't know why)
> where we get the error:
>
> *logger_LM_ERR(): Exception occurred: Traceback (most recent call last):
> File "mypythonExample.py", line XXX, in SendPushNotification
> requestUri = self.ExtractURIFromHeader(msg.getHeader("to"))
> File "mypythonExample.py", line XXX, in ExtractURIFromHeader
> m= self.uriPattern.match(header);
> TypeError: an integer is required*
>
> We tried to analyze the cause of this error, but we didn't find any problem
> with the message itself (the message is complete, with the *to *and *from
> *correctly filled).
>
> So, to avoid using the python regex, we have decided to pass parameters to
> the python script (callId, from and to URI):
>
> *def SendPushRequest(self, msg, fromUri, toUri, callid)*
>
> But it seems python_exec doesn't support more than 2 parameters ($mb and
> another one). Is this exact? If this is the case, how can we pass several
> parameters from kamailio.cfg?
>
> Thx for your help.
>
> Regards
>
> Giovanni
>
>
>
>
>
> --
> View this message in context: http://sip-router.1086192.n5.nabble.com/python-exec-and-parameters-tp155803.html
> Sent from the Users mailing list archive at Nabble.com.
>
> _______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
> sr-users@lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

--
Daniel-Constantin Mierla
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio Advanced Training - Mar 6-8 (Europe) and Mar 20-22 (USA) - www.asipto.com
Kamailio World Conference - May 8-10, 2017 - www.kamailioworld.com


_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users


-- 
Daniel-Constantin Mierla
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio Advanced Training - Mar 6-8 (Europe) and Mar 20-22 (USA) - www.asipto.com
Kamailio World Conference - May 8-10, 2017 - www.kamailioworld.com