Mailman-web showing "An error occurred while processing your request."
I'm trying to manage 2 held messages in a specific list and I'm getting this error below when I click on /held_messages. It never happened before.
My versions are:
(venv) [mailman@listas ~]$ pip list -o | grep -E 'posto|hyper|mailma|djang'
Package Version Latest Type
django-allauth 0.44.0 0.52.0 sdist django-appconf 1.0.4 1.0.5 wheel django-compressor 2.4 4.3.1 wheel django-extensions 3.1.0 3.2.1 wheel django-haystack 3.0 3.2.1 sdist django-mailman3 1.3.5 1.3.9 sdist django-picklefield 3.0.1 3.1 wheel django-q 1.3.4 1.3.9 wheel djangorestframework 3.12.2 3.14.0 wheel mailman 3.3.2 3.3.8 sdist mailman-hyperkitty 1.1.0 1.2.1 sdist mailman-web 0.0.3 0.0.5 wheel mailmanclient 3.3.2 3.3.5 sdist postorius 1.3.3 1.3.8 sdist
==> mailmanweb.log <== ERROR 2023-02-08 16:01:30,149 1516 django.request Internal Server Error: /mailman3/lists/mylist.domain.com/held_messages Traceback (most recent call last): File "/opt/mailman/venv/lib64/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view return view_func(request, *args, **kwargs) File "/opt/mailman/venv/lib64/python3.6/site-packages/postorius/auth/decorators.py", line 60, in wrapper return fn(*args, **kwargs) File "/opt/mailman/venv/lib64/python3.6/site-packages/postorius/views/list.py", line 531, in list_moderation return render(request, 'postorius/lists/held_messages.html', context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/shortcuts.py", line 19, in render content = loader.render_to_string(template_name, context, request, using=using) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/loader.py", line 62, in render_to_string return template.render(context, request) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/backends/django.py", line 61, in render return self.template.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 171, in render return self._render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 163, in _render return self.nodelist.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 936, in render bit = node.render_annotated(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 903, in render_annotated return self.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/loader_tags.py", line 150, in render return compiled_parent._render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 163, in _render return self.nodelist.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 936, in render bit = node.render_annotated(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 903, in render_annotated return self.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/loader_tags.py", line 62, in render result = block.nodelist.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 936, in render bit = node.render_annotated(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 903, in render_annotated return self.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/defaulttags.py", line 309, in render return nodelist.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 936, in render bit = node.render_annotated(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 903, in render_annotated return self.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/defaulttags.py", line 209, in render nodelist.append(node.render_annotated(context)) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 903, in render_annotated return self.render(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 986, in render output = self.filter_expression.resolve(context) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/template/base.py", line 697, in resolve new_obj = func(obj, *arg_vals) File "/opt/mailman/venv/lib64/python3.6/site-packages/postorius/templatetags/date_helpers.py", line 30, in datetime_parse return parse_datetime(value) File "/opt/mailman/venv/lib64/python3.6/site-packages/django/utils/dateparse.py", line 107, in parse_datetime match = datetime_re.match(value) TypeError: expected string or bytes-like object
Another user who reported this simply removed the underlying files. Turned out for whatever reason a couple of malformed messages (missing headers and message bodies) were stuck there. Of course, the program tries to parse those messages into the held messages view. That's likely generating your error.
On my 3.3.3 installation I had similar errors related to permissions so it was easier to identify where the messages were stored on disk and correct the permissions. Don't recall off the top of my head where the held messages are stored on disk tho...
On 2/8/23 08:34, C. Souza wrote:
I'm trying to manage 2 held messages in a specific list and I'm getting this error below when I click on /held_messages. It never happened before. ... ==> mailmanweb.log <== ERROR 2023-02-08 16:01:30,149 1516 django.request Internal Server Error: /mailman3/lists/mylist.domain.com/held_messages Traceback (most recent call last): ... File "/opt/mailman/venv/lib64/python3.6/site-packages/django/utils/dateparse.py", line 107, in parse_datetime match = datetime_re.match(value) TypeError: expected string or bytes-like object
I'm not certain, but it looks like one of the held messages has a bad or possibly missing Date: header. Working around this is tricky. You can do the following in mailman shell.
$ mailman shell -l list@example.com
Welcome to the GNU Mailman shell
Use commit() to commit changes.
Use abort() to discard changes since the last commit.
Exit with ctrl+D does an implicit commit() but exit() does not.
The variable 'm' is the list.example.com mailing list
>>> requests = IListRequests(m)
>>> msgstor = getUtility(IMessageStore)
>>> for request in requests.held_requests:
... key, data = requests.get_request(request.id)
... if data['_request_type'] == 'held_message':
... print(f'request ID = {request.id}Message-ID = {key}\n '
... f'message = {msgstor.get_message_by_id(key)}')
...
This will print for each held message output like
request ID = nnn
Message-ID = <the message id>
message = the message content
You can then handle these messages with
>>> from mailman.app.moderator import handle_message
>>> handle_message(m, nnn, action)
where nnn is the request ID and action is either Action.discard to
discard the message or Action.accept to accept it. And finally
>>> commit()
If you decide you want to edit the message content before accepting it, you could find the message in the file system. One of the headers in the displayed message is something like
Message-ID-Hash: IWL2EUW3FT7IIUA3QYTZEX4W4JBZ26HL
the message is saved as a python pickle in the file system in Mailman's var/messages/ directory. This has subdirectories of the first two characters of the Message-ID-Hash value and those have subdirectories of the second two characters of the Message-ID-Hash value, so if the above were the actual Message-ID-Hash the pickle would be at var/messages/IW/L2/IWL2EUW3FT7IIUA3QYTZEX4W4JBZ26HL. You would need to pickle the new message content and save that over the existing file.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Hello Guys,
Thank you for the help.
Mark, I followed your recommendation running your code and it's done, problem solved.
Just for curiosity, does anyone know the reasons for this kind of problem and how to avoid it?
Thank you very much.
-- Carlos Adean
On Thu, Feb 9, 2023 at 1:55 AM Mark Sapiro <mark@msapiro.net> wrote:
On 2/8/23 08:34, C. Souza wrote:
I'm trying to manage 2 held messages in a specific list and I'm getting this error below when I click on /held_messages. It never happened before. ... ==> mailmanweb.log <== ERROR 2023-02-08 16:01:30,149 1516 django.request Internal Server Error: /mailman3/lists/mylist.domain.com/held_messages Traceback (most recent call last): ... File
"/opt/mailman/venv/lib64/python3.6/site-packages/django/utils/dateparse.py",
line 107, in parse_datetime match = datetime_re.match(value) TypeError: expected string or bytes-like object
I'm not certain, but it looks like one of the held messages has a bad or possibly missing Date: header. Working around this is tricky. You can do the following in mailman shell.
$ mailman shell -l list@example.com Welcome to the GNU Mailman shell Use commit() to commit changes. Use abort() to discard changes since the last commit. Exit with ctrl+D does an implicit commit() but exit() does not. The variable 'm' is the list.example.com mailing list >>> requests = IListRequests(m) >>> msgstor = getUtility(IMessageStore) >>> for request in requests.held_requests: ... key, data = requests.get_request(request.id) ... if data['_request_type'] == 'held_message': ... print(f'request ID = {request.id}Message-ID = {key}\n ' ... f'message = {msgstor.get_message_by_id(key)}') ... This will print for each held message output like request ID = nnn Message-ID = <the message id> message = the message content You can then handle these messages with >>> from mailman.app.moderator import handle_message >>> handle_message(m, nnn, action) where nnn is the request ID and action is either Action.discard to discard the message or Action.accept to accept it. And finally >>> commit()
If you decide you want to edit the message content before accepting it, you could find the message in the file system. One of the headers in the displayed message is something like
Message-ID-Hash: IWL2EUW3FT7IIUA3QYTZEX4W4JBZ26HL
the message is saved as a python pickle in the file system in Mailman's var/messages/ directory. This has subdirectories of the first two characters of the Message-ID-Hash value and those have subdirectories of the second two characters of the Message-ID-Hash value, so if the above were the actual Message-ID-Hash the pickle would be at var/messages/IW/L2/IWL2EUW3FT7IIUA3QYTZEX4W4JBZ26HL. You would need to pickle the new message content and save that over the existing file.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mailman-users mailing list -- mailman-users@mailman3.org To unsubscribe send an email to mailman-users-leave@mailman3.org https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/ Archived at: https://lists.mailman3.org/archives/list/mailman-users@mailman3.org/message/...
This message sent to skooperit@gmail.com
On 2/9/23 07:57, C. Souza wrote:
Just for curiosity, does anyone know the reasons for this kind of problem and how to avoid it?
Cause: Something in the specific email message.
Avoidance: Possibly if we knew what the specific issue was or could see the held messages as displayed by the mailman shell script I provided, we could detect the issue and do something about it. Possibly Postorius could catch this and be more graceful about it, but again we'd probably need a message that triggers this issue.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
participants (3)
-
C. Souza
-
jbernal.web.dev@gmail.com
-
Mark Sapiro