Cannot load python modules via webadmin w/ Debian 12/Python 3.11.x/znc-1.9.x #1031

Closed
opened 2026-10-05 04:59:22 +02:00 by adam · 2 comments
Owner

I've managed to replicate this on Debian 12, both a VPS and my laptop.

Issue 1: Cannot see/load/unload python modules in webadmin.
Issue 2: Clicking the Save and return OR Save and continue button causes znc to unload all python modules that are loaded.

Both laptop and VPS:

$ python --version
Python 3.11.2

Laptop:

kindone@laptop:~$ znc -v
ZNC 1.9.x-git-286-bf5805d9 - https://znc.in
IPv6: yes, SSL: yes, DNS: threads, charset: yes, i18n: no, Argon2: yes

VPS:

kindone@debian-s-1vcpu-1gb-nyc1-01 $ znc -v
ZNC 1.9.x-git-259-3779a9ba - https://znc.in
IPv6: yes, SSL: yes, DNS: threads, charset: yes, i18n: no

Laptop output:

[2023-10-23 18:48:34.655986] CTemplate::AppendPath(.//webskins/_default_//tmpl/) == [./webskins/_default_/tmpl/]
[2023-10-23 18:48:34.656307]     Found  [/usr/share/znc/modules/webadmin/tmpl/add_edit_user.tmpl]
[2023-10-23 18:48:34.656397] CTemplate::PrependPath(add_edit_user.tmpl/..) == [./]
[2023-10-23 18:48:34.656517] Set template file to [/usr/share/znc/modules/webadmin/tmpl/add_edit_user.tmpl]
[2023-10-23 18:48:34.756433] modpython tried to get info about [/tmp/modules/] (2) but: Traceback (most recent call last):\x0A  File "/usr/lib/x86_64-linux-gnu/znc/modpython/znc.py", line 945, in get_mod_info_path\x0A    x = imp.find_module(modname, [path])\x0A        ^^^\x0ANameError: name 'imp' is not defined\x0A
[2023-10-23 18:48:34.757042] modpython tried to get info about [/tmp/modules/] (2) but: Traceback (most recent call last):\x0A  File "/usr/lib/x86_64-linux-gnu/znc/modpython/znc.py", line 945, in get_mod_info_path\x0A    x = imp.find_module(modname, [path])\x0A        ^^^\x0ANameError: name 'imp' is not defined\x0A
[2023-10-23 18:48:34.757947] modpython tried to get info about [/usr/lib/x86_64-linux-gnu/znc/] (2) but: Traceback (most recent call last):\x0A  File "/usr/lib/x86_64-linux-gnu/znc/modpython/znc.py", line 945, in get_mod_info_path\x0A    x = imp.find_module(modname, [path])\x0A        ^^^\x0ANameError: name 'imp' is not defined\x0A
[2023-10-23 18:48:34.758284] modpython tried to get info about [/usr/lib/x86_64-linux-gnu/znc/] (2) but: Traceback (most recent call last):\x0A  File "/usr/lib/x86_64-linux-gnu/znc/modpython/znc.py", line 945, in get_mod_info_path\x0A    x = imp.find_module(modname, [path])\x0A        ^^^\x0ANameError: name 'imp' is not defined\x0A

My znc.py file matches what is currently in git on both laptop and VPS.

kindone@laptop:~$ sha1sum /usr/lib/x86_64-linux-gnu/znc/modpython/znc.py
fd61d8e2dea3c8061415b799f0c233bf2331e668  /usr/lib/x86_64-linux-gnu/znc/modpython/znc.py
kindone@laptop:~$ sha1sum znc-dev/modules/modpython/znc.py
fd61d8e2dea3c8061415b799f0c233bf2331e668  znc-dev/modules/modpython/znc.py
I've managed to replicate this on Debian 12, both a VPS and my laptop. Issue 1: Cannot see/load/unload python modules in webadmin. Issue 2: Clicking the ```Save and return``` OR ```Save and continue``` button causes znc to unload all python modules that are loaded. Both laptop and VPS: ``` $ python --version Python 3.11.2 ``` Laptop: ``` kindone@laptop:~$ znc -v ZNC 1.9.x-git-286-bf5805d9 - https://znc.in IPv6: yes, SSL: yes, DNS: threads, charset: yes, i18n: no, Argon2: yes ``` VPS: ``` kindone@debian-s-1vcpu-1gb-nyc1-01 $ znc -v ZNC 1.9.x-git-259-3779a9ba - https://znc.in IPv6: yes, SSL: yes, DNS: threads, charset: yes, i18n: no ``` Laptop output: ``` [2023-10-23 18:48:34.655986] CTemplate::AppendPath(.//webskins/_default_//tmpl/) == [./webskins/_default_/tmpl/] [2023-10-23 18:48:34.656307] Found [/usr/share/znc/modules/webadmin/tmpl/add_edit_user.tmpl] [2023-10-23 18:48:34.656397] CTemplate::PrependPath(add_edit_user.tmpl/..) == [./] [2023-10-23 18:48:34.656517] Set template file to [/usr/share/znc/modules/webadmin/tmpl/add_edit_user.tmpl] [2023-10-23 18:48:34.756433] modpython tried to get info about [/tmp/modules/] (2) but: Traceback (most recent call last):\x0A File "/usr/lib/x86_64-linux-gnu/znc/modpython/znc.py", line 945, in get_mod_info_path\x0A x = imp.find_module(modname, [path])\x0A ^^^\x0ANameError: name 'imp' is not defined\x0A [2023-10-23 18:48:34.757042] modpython tried to get info about [/tmp/modules/] (2) but: Traceback (most recent call last):\x0A File "/usr/lib/x86_64-linux-gnu/znc/modpython/znc.py", line 945, in get_mod_info_path\x0A x = imp.find_module(modname, [path])\x0A ^^^\x0ANameError: name 'imp' is not defined\x0A [2023-10-23 18:48:34.757947] modpython tried to get info about [/usr/lib/x86_64-linux-gnu/znc/] (2) but: Traceback (most recent call last):\x0A File "/usr/lib/x86_64-linux-gnu/znc/modpython/znc.py", line 945, in get_mod_info_path\x0A x = imp.find_module(modname, [path])\x0A ^^^\x0ANameError: name 'imp' is not defined\x0A [2023-10-23 18:48:34.758284] modpython tried to get info about [/usr/lib/x86_64-linux-gnu/znc/] (2) but: Traceback (most recent call last):\x0A File "/usr/lib/x86_64-linux-gnu/znc/modpython/znc.py", line 945, in get_mod_info_path\x0A x = imp.find_module(modname, [path])\x0A ^^^\x0ANameError: name 'imp' is not defined\x0A ``` My ```znc.py``` file matches what is currently in git on both laptop and VPS. ``` kindone@laptop:~$ sha1sum /usr/lib/x86_64-linux-gnu/znc/modpython/znc.py fd61d8e2dea3c8061415b799f0c233bf2331e668 /usr/lib/x86_64-linux-gnu/znc/modpython/znc.py kindone@laptop:~$ sha1sum znc-dev/modules/modpython/znc.py fd61d8e2dea3c8061415b799f0c233bf2331e668 znc-dev/modules/modpython/znc.py ``` <!-- github-sync-id:1958171621 -->
adam closed this issue 2026-10-05 04:59:22 +02:00
Author
Owner

I think this was broken by b3b38956a7. There's still usage of imp in get_mod_info_path (https://github.com/znc/znc/blob/master/modules/modpython/znc.py#L943C5-L943C22).

I think this was broken by b3b38956a7a5d909b6aa964ad432e418c93ce826. There's still usage of `imp` in `get_mod_info_path` (https://github.com/znc/znc/blob/master/modules/modpython/znc.py#L943C5-L943C22). <!-- github-comment-id:1776208098 -->
Author
Owner

@thesamesam Suggested I add import imp, that seems to fix the issue for me for now.

imp is depreciated and has been removed in Python 3.12 (released October 2, 2023.)

Better solution would be to use the suggestions in the link below but I don't know enough python to figure it out.

https://docs.python.org/dev/whatsnew/3.12.html#imp

I've created a test for this issue that passes with the included import imp.

kindone@laptop:~/znc-dev$ git diff
diff --git a/modules/modpython/znc.py b/modules/modpython/znc.py
index 4e8fc295..d81e635e 100644
--- a/modules/modpython/znc.py
+++ b/modules/modpython/znc.py
@@ -23,6 +23,8 @@ if os.environ.get('ZNC_MODPYTHON_COVERAGE'):

 from functools import wraps
 import collections.abc
+# DEPRECIATED
+import imp
 import importlib.abc
 import importlib.machinery
 import importlib.util
diff --git a/test/integration/tests/scripting.cpp b/test/integration/tests/scripting.cpp
index 24a45038..928d7fec 100644
--- a/test/integration/tests/scripting.cpp
+++ b/test/integration/tests/scripting.cpp
@@ -64,6 +64,23 @@ TEST_F(ZNCTest, Modpython) {
     ircd.ReadUntil("JOIN #a\xEF\xBF\xBD");
 }

+// Test if python modules are viewable via *status.
+// https://github.com/znc/znc/issues/1884
+TEST_F(ZNCTest, Modpython2) {
+    if (QProcessEnvironment::systemEnvironment().value(
+            "DISABLED_ZNC_PERL_PYTHON_TEST") == "1") {
+        return;
+    }
+    auto znc = Run();
+    znc->CanLeak();
+    auto ircd = ConnectIRCd();
+    auto client = LoginClient();
+    client.Write("znc loadmod modpython");
+    client.Write("znc listavailmods");
+    client.ReadUntil(":*status!status@znc.in PRIVMSG nick :\x02 pyeval\x0F: Evaluates python code");
+}
+
+
 TEST_F(ZNCTest, ModpythonSocket) {
     if (QProcessEnvironment::systemEnvironment().value(
             "DISABLED_ZNC_PERL_PYTHON_TEST") == "1") {

Test results:

kindone@laptop:~/znc-dev$ test/integration/inttest --gtest_filter=*Modpython2
Note: Google Test filter = *Modpython2
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from ZNCTest
[ RUN      ] ZNCTest.Modpython2
// snip...
[2023-10-25 18:16:23.707135] (user/test) CLI -> ZNC [znc loadmod modpython]
[2023-10-25 18:16:24.059875] (user/test) ZNC -> CLI [:*status!status@znc.in PRIVMSG nick :Loaded module modpython: [/usr/lib/x86_64-linux-gnu/znc/modpython.so]]
[2023-10-25 18:16:24.060363] (user/test) CLI -> ZNC [znc listavailmods]
// snip...
[2023-10-25 18:16:24.163481] (user/test) ZNC -> CLI [:*status!status@znc.in PRIVMSG nick :\x02 pyeval\x0F: Evaluates python code]
// snip... 
[2023-10-25 18:16:24.223617] IRC::user::test == Disconnected()
[2023-10-25 18:16:24.223832] USR::user == Disconnected()
[ ** ] Exiting
[       OK ] ZNCTest.Modpython2 (2001 ms)
[----------] 1 test from ZNCTest (2001 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (2001 ms total)
[  PASSED  ] 1 test.
@thesamesam Suggested I add ```import imp```, that seems to fix the issue for me for now. ```imp``` is depreciated and has been removed in Python 3.12 (released October 2, 2023.) Better solution would be to use the suggestions in the link below but I don't know enough python to figure it out. https://docs.python.org/dev/whatsnew/3.12.html#imp I've created a test for this issue that passes with the included ```import imp```. ``` kindone@laptop:~/znc-dev$ git diff diff --git a/modules/modpython/znc.py b/modules/modpython/znc.py index 4e8fc295..d81e635e 100644 --- a/modules/modpython/znc.py +++ b/modules/modpython/znc.py @@ -23,6 +23,8 @@ if os.environ.get('ZNC_MODPYTHON_COVERAGE'): from functools import wraps import collections.abc +# DEPRECIATED +import imp import importlib.abc import importlib.machinery import importlib.util diff --git a/test/integration/tests/scripting.cpp b/test/integration/tests/scripting.cpp index 24a45038..928d7fec 100644 --- a/test/integration/tests/scripting.cpp +++ b/test/integration/tests/scripting.cpp @@ -64,6 +64,23 @@ TEST_F(ZNCTest, Modpython) { ircd.ReadUntil("JOIN #a\xEF\xBF\xBD"); } +// Test if python modules are viewable via *status. +// https://github.com/znc/znc/issues/1884 +TEST_F(ZNCTest, Modpython2) { + if (QProcessEnvironment::systemEnvironment().value( + "DISABLED_ZNC_PERL_PYTHON_TEST") == "1") { + return; + } + auto znc = Run(); + znc->CanLeak(); + auto ircd = ConnectIRCd(); + auto client = LoginClient(); + client.Write("znc loadmod modpython"); + client.Write("znc listavailmods"); + client.ReadUntil(":*status!status@znc.in PRIVMSG nick :\x02 pyeval\x0F: Evaluates python code"); +} + + TEST_F(ZNCTest, ModpythonSocket) { if (QProcessEnvironment::systemEnvironment().value( "DISABLED_ZNC_PERL_PYTHON_TEST") == "1") { ``` Test results: ``` kindone@laptop:~/znc-dev$ test/integration/inttest --gtest_filter=*Modpython2 Note: Google Test filter = *Modpython2 [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from ZNCTest [ RUN ] ZNCTest.Modpython2 // snip... [2023-10-25 18:16:23.707135] (user/test) CLI -> ZNC [znc loadmod modpython] [2023-10-25 18:16:24.059875] (user/test) ZNC -> CLI [:*status!status@znc.in PRIVMSG nick :Loaded module modpython: [/usr/lib/x86_64-linux-gnu/znc/modpython.so]] [2023-10-25 18:16:24.060363] (user/test) CLI -> ZNC [znc listavailmods] // snip... [2023-10-25 18:16:24.163481] (user/test) ZNC -> CLI [:*status!status@znc.in PRIVMSG nick :\x02 pyeval\x0F: Evaluates python code] // snip... [2023-10-25 18:16:24.223617] IRC::user::test == Disconnected() [2023-10-25 18:16:24.223832] USR::user == Disconnected() [ ** ] Exiting [ OK ] ZNCTest.Modpython2 (2001 ms) [----------] 1 test from ZNCTest (2001 ms total) [----------] Global test environment tear-down [==========] 1 test from 1 test case ran. (2001 ms total) [ PASSED ] 1 test. ``` <!-- github-comment-id:1780163156 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/znc#1031