modpython throws an AttributeError when trying to read web request headers #670

Open
opened 2026-10-05 04:37:30 +02:00 by adam · 2 comments
Owner

Python module snippet:

    def OnWebPreRequest(self, WebSock, sPageName):
        http_headers = WebSock.m_msHeaders

First line of that function causes this traceback:

modpython: <no user>/httpadmin/OnWebPreRequest failed: Traceback (most recent call last):
  File "/home/darren/.znc/modules/httpadmin.py", line 91, in OnWebPreRequest
    http_headers = WebSock.m_msHeaders
  File "/usr/lib/znc/modpython/znc_core.py", line 6569, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, CWebSock, name)
  File "/usr/lib/znc/modpython/znc_core.py", line 74, in _swig_getattr
    return _swig_getattr_nondynamic(self, class_type, name, 0)
  File "/usr/lib/znc/modpython/znc_core.py", line 69, in _swig_getattr_nondynamic
    return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/29561929-modpython-throws-an-attributeerror-when-trying-to-read-web-request-headers?utm_campaign=plugin&utm_content=tracker%2F1759&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1759&utm_medium=issues&utm_source=github).
Python module snippet: ``` python def OnWebPreRequest(self, WebSock, sPageName): http_headers = WebSock.m_msHeaders ``` First line of that function causes this traceback: ``` modpython: <no user>/httpadmin/OnWebPreRequest failed: Traceback (most recent call last): File "/home/darren/.znc/modules/httpadmin.py", line 91, in OnWebPreRequest http_headers = WebSock.m_msHeaders File "/usr/lib/znc/modpython/znc_core.py", line 6569, in <lambda> __getattr__ = lambda self, name: _swig_getattr(self, CWebSock, name) File "/usr/lib/znc/modpython/znc_core.py", line 74, in _swig_getattr return _swig_getattr_nondynamic(self, class_type, name, 0) File "/usr/lib/znc/modpython/znc_core.py", line 69, in _swig_getattr_nondynamic return object.__getattr__(self, name) AttributeError: type object 'object' has no attribute '__getattr__' ``` ## <bountysource-plugin> --- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/29561929-modpython-throws-an-attributeerror-when-trying-to-read-web-request-headers?utm_campaign=plugin&utm_content=tracker%2F1759&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1759&utm_medium=issues&utm_source=github). </bountysource-plugin> <!-- github-sync-id:124687380 -->
Author
Owner

I'm seeing the same issue on my end. Code to replicate the issue:

class api(znc.Module):
    def OnWebPreRequest(self, WebSock, sPageName):
        users = dict(znc.CZNC.Get().GetUserMap())

        for name in users:
            # blockuser module
            mod_blockuser = znc.CZNC.Get().GetModules().FindModule('blockuser')

            if mod_blockuser:
                if mod_blockuser.HasNV(users[name].GetUserName()):
                    # ....
        # ....

Here is the exception from the original script, but alas the same issue it looks like:

Traceback (most recent call last):
  File "/home/znc/.znc/modules/api.py", line 98, in OnWebPreRequest
    if mod_blockuser.HasNV(users[name].GetUserName()):
  File "/home/znc/znc/modules/modpython/znc_core.py", line 3689, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, CModule, name)
  File "/home/znc/znc/modules/modpython/znc_core.py", line 74, in _swig_getattr
    return _swig_getattr_nondynamic(self, class_type, name, 0)
  File "/home/znc/znc/modules/modpython/znc_core.py", line 69, in _swig_getattr_nondynamic
    return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'

I'm receiving this as of the latest 1.6.3 source tar.gz, manually compiled.

I'm seeing the same issue on my end. Code to replicate the issue: ``` python class api(znc.Module): def OnWebPreRequest(self, WebSock, sPageName): users = dict(znc.CZNC.Get().GetUserMap()) for name in users: # blockuser module mod_blockuser = znc.CZNC.Get().GetModules().FindModule('blockuser') if mod_blockuser: if mod_blockuser.HasNV(users[name].GetUserName()): # .... # .... ``` Here is the exception from the original script, but alas the same issue it looks like: ``` Traceback (most recent call last): File "/home/znc/.znc/modules/api.py", line 98, in OnWebPreRequest if mod_blockuser.HasNV(users[name].GetUserName()): File "/home/znc/znc/modules/modpython/znc_core.py", line 3689, in <lambda> __getattr__ = lambda self, name: _swig_getattr(self, CModule, name) File "/home/znc/znc/modules/modpython/znc_core.py", line 74, in _swig_getattr return _swig_getattr_nondynamic(self, class_type, name, 0) File "/home/znc/znc/modules/modpython/znc_core.py", line 69, in _swig_getattr_nondynamic return object.__getattr__(self, name) AttributeError: type object 'object' has no attribute '__getattr__' ``` I'm receiving this as of the latest 1.6.3 source tar.gz, manually compiled. <!-- github-comment-id:187999106 -->
Author
Owner

Looks like my issue may not be 100% related. I was able to track down that it looks like CModule::HasNV was removed sometime before and/or up to 1.6.3, and now CModule::ExistsNV has taken it's place. I am not seeing that the documentation on this matter has been properly updated, as I had to scramble through the c++ source to find it.

Still not quite sure if it's related, but...

Looks like my issue may not be 100% related. I was able to track down that it looks like `CModule::HasNV` was removed sometime before and/or up to 1.6.3, and now `CModule::ExistsNV` has taken it's place. I am not seeing that the documentation on this matter has been properly updated, as I had to scramble through the c++ source to find it. Still not quite sure if it's related, but... <!-- github-comment-id:188101399 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/znc#670