### Description I am using Kemi with the app_python3 module. I was getting what appeared to be random TypeError exceptions thrown within the Kamailio app_python3 module. I later discovered that this only happened when calling a Kamailio function that exceeded the duration specified in the latency_limit_action core parameter. Also, the line printed in the logs displayed Null values in the 'file:' and 'func:' fields.
#### Reproduction To reproduce the issue: 1. You must be using Kemi with the app_python3 module, with the cfgengine set to python.
2. Set the following in your kamailio.cfg file: ``` latency_log=2 latency_limit_action=100000
``` 3. Run a Kemi function call that takes more time than the latency_limi_action set above. You may have to lower it if your computer is a fast runner. Here is my suggested code: ``` jsreload = dict() jsreload["jsonrpc"] = "2.0" jsreload["method"] = "tls.reload" jsreload["id"] = 1 KSR.jsonrpcs.exec(json.dumps(jsreload))
``` 4. Use python version 3.11
#### Log Messages
45(324) INFO: app_python3 [apy_kemi.c:377]: sr_apy_kemi_exec_func(): alert - action KSR.jsonrpcs.exec(...) took too long [752946 ms] (file:(null) func:(null) line:491) 45(324) ERROR: app_python3 [python_support.c:167]: python_handle_exception(): apy_exec: ksr_rtimer_dodebug(rtimer): Unhandled exception in the Python code: TypeError: expected bytes, str found
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/etc/kamailio/kamailio.py", line 491, in ksr_rtimer_dodebug KSR.jsonrpcs.exec(json.dumps(jsreload)) SystemError: <built-in function exec> returned a result with an exception set
### Possible Solutions The solution is to replace PyBytes_AsString(..) calls with calls to PyUnicode_AsUTF8(..) in the PY_VERSION_HEX >= 0x030B0000 block of apy_kemi.c. The PyBytes_AsString expects a Bytes value but reeives a Unicode value instead, thus causing the TypeError exception. Enclosed is a patch file with the fix implemented:
[kamailio-5.8.2.patch.txt](https://github.com/user-attachments/files/16195734/kamailio-5.8.2.patch.txt)
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` # kamailio -v version: kamailio 5.8.2 (x86_64/linux) 3fa5f4 flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, MEM_JOIN_FREE, 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_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_SEND_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: 3fa5f4 compiled on 09:58:55 Jul 12 2024 with gcc 12.2.0
```
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `lsb_release -a` and `uname -a`) -->
``` # uname -a Linux xxxxxxxxxxxxxxxxxxx 5.10.0-30-amd64 #1 SMP Debian 5.10.218-1 (2024-06-01) x86_64 GNU/Linux ```
This issue is stale because it has been open 6 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.
Thanks for the report. Do you could create a PR with the patch mentioned above? Then it could be easily reviewed and merged.
Hello,
I have tried but it seems I do not have the necessary permission to do so. Here is what I did: 1. git clone https://github.com/kamailio/kamailio.git 2. git branch michel/bug_fixes 3. git checkout michel/bug_fixes 4. Make my changes. 5. git add . 6. git commit 7. git push --set-upstream origin michel/bug_fixes This didn't work so I installed the github cli application. 8. gh auth 9. gh auth setup-git 10. git push --set-upstream origin michel/bug_fixes This time it failed with the following: remote: Permission to kamailio/kamailio.git denied to michelpelletier07. fatal: unable to access 'https://github.com/kamailio/kamailio.git/': The requested URL returned error: 403
Regards,
Michel Pelletier
On Tue, Aug 27, 2024 at 2:28 AM Henning Westerholt ***@***.***> wrote:
Thanks for the report. Do you could create a PR with the patch mentioned above? Then it could be easily reviewed and merged.
— Reply to this email directly, view it on GitHub https://github.com/kamailio/kamailio/issues/3915#issuecomment-2311884535, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYYXXDAKU3VRO6EV4ASEFTZTQ2CHAVCNFSM6AAAAABKZCXBZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJRHA4DINJTGU . You are receiving this because you authored the thread.Message ID: ***@***.***>
@michelpelletier07 You missed an important step, you need to create a private fork from the public kamailio repository first. Then you do the changes in your fork and push them there. Then you can create the PR against the kamailio official repository. Refer e.g. to this documentation: [link](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/pr...)
Hi,
I created the PR. Thanks for your help. Regards,
Michel Pelletier
On Wed, Aug 28, 2024 at 8:38 AM Henning Westerholt ***@***.***> wrote:
@michelpelletier07 https://github.com/michelpelletier07 You missed an important step, you need to create a private fork from the public kamailio repository first. Then you do the changes in your fork and push them there. Then you can create the PR against the kamailio official repository. Refer e.g. to this documentation: link https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork
— Reply to this email directly, view it on GitHub https://github.com/kamailio/kamailio/issues/3915#issuecomment-2315524718, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYYXXHUCVX5SRXXY4VBIB3ZTXOE5AVCNFSM6AAAAABKZCXBZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJVGUZDINZRHA . You are receiving this because you were mentioned.Message ID: ***@***.***>
PR link #3959
Merged.
Closed #3915 as completed.