I'm using mailman 1.1. One of our lists consistently generates the following python traceback in the mailman error log whenever a message is posted to the list.
Dec 01 13:22:45 1999 post: Traceback (innermost last): post: File "/usr/local/mailman/scripts/mailowner", line 45, in ? post: if not mlist.bounce_processing or not mlist.ScanMessage(msg): post: File "/usr/local/mailman/Mailman/Bouncer.py", line 449, in ScanMessage post: self.RegisterBounce(who, msg) post: File "/usr/local/mailman/Mailman/Bouncer.py", line 138, in RegisterBounce post: self.LogMsg("bounce", report + "exceeded limits") post: File "/usr/local/mailman/Mailman/MailList.py", line 834, in LogMsg post: logf.write(msg % args + '\n') post: TypeError : not enough arguments for format string
I've had a look at the call to LogMsg() in MailList.py from RegisterBounce() in Bouncer.py, so I sort of where the error is happening. As far as I can tell, there must be some instances where LogMsg is being called with a "msg" argument that contains % variable substitutions that have not yet been satisfied, but with an empty or insufficient "args" tuple. So, when LogMsg calls logf.write(msg % args + '\n'), the % substitution fails.
It seems that, in general, the use of LogMsg is inconsistent. In some cases, a variable length args tuple is passed to LogMsg and the string formatting is done within LogMsg, but in many other cases any string formatting is done before the call to LogMsg and LogMsg is called without an args tuple.
It's entirely possible that something will call LogMsg with a "msg" argument that contains a valid % substitution string even though they did not intend for a % substitution to happen. I think this is what may be happening in my case - the RegisterBounce() function builds the "msg" string from other variable strings and one of these strings may contain a % substitution string. This msg string is then passed to LogMsg but without an args tuple to satisfy the % substitution.
I'm no Python expert - I just started learning it a few weeks ago - but I'm trying to think of ways to debug this, or handle the situation more gracefully. I've been poking through the Python books I have and looking at the exception handling stuff. I've come up with the following simple idea for handling this in LogMsg(). Any opinions about whether this is a good idea, whether it will work, or whether there is a better way to approach this problem?
try:
logf.write(msg % args + '\n')
except:
logf.write(msg + '\n')
--
Todd Pfaff \ Email: pfaff@mcmaster.ca
Computing and Information Services \ Voice: (905) 525-9140 x22920
ABB 132 \ FAX: (905) 528-3773
McMaster University
Hamilton, Ontario, Canada L8S 4M1 \
Sure enough! This was exactly the problem! After applying the 'try: except:' fix I suggested below I no longer get the error traceback from LogMsg and I see the following in the bounce log. It was the email address string containing % characters in LogMsg called from RegisterBounce that was causing the failure.
Dec 02 11:47:26 1999 cdn-nucl-l: DXS9%OPS%DCPP@bangate.pge.com - exceeded limits Dec 02 11:47:26 1999 cdn-nucl-l: disabled dxs9%ops%dcpp@bangate.pge.com Dec 02 11:47:27 1999 cdn-nucl-l: gonuke@bigfoot.com - first
n Thu, 2 Dec 1999, Todd Pfaff wrote:
I'm using mailman 1.1. One of our lists consistently generates the following python traceback in the mailman error log whenever a message is posted to the list.
Dec 01 13:22:45 1999 post: Traceback (innermost last): post: File "/usr/local/mailman/scripts/mailowner", line 45, in ? post: if not mlist.bounce_processing or not mlist.ScanMessage(msg): post: File "/usr/local/mailman/Mailman/Bouncer.py", line 449, in ScanMessage post: self.RegisterBounce(who, msg) post: File "/usr/local/mailman/Mailman/Bouncer.py", line 138, in RegisterBounce post: self.LogMsg("bounce", report + "exceeded limits") post: File "/usr/local/mailman/Mailman/MailList.py", line 834, in LogMsg post: logf.write(msg % args + '\n') post: TypeError : not enough arguments for format string
I've had a look at the call to LogMsg() in MailList.py from RegisterBounce() in Bouncer.py, so I sort of where the error is happening. As far as I can tell, there must be some instances where LogMsg is being called with a "msg" argument that contains % variable substitutions that have not yet been satisfied, but with an empty or insufficient "args" tuple. So, when LogMsg calls logf.write(msg % args + '\n'), the % substitution fails.
It seems that, in general, the use of LogMsg is inconsistent. In some cases, a variable length args tuple is passed to LogMsg and the string formatting is done within LogMsg, but in many other cases any string formatting is done before the call to LogMsg and LogMsg is called without an args tuple.
It's entirely possible that something will call LogMsg with a "msg" argument that contains a valid % substitution string even though they did not intend for a % substitution to happen. I think this is what may be happening in my case - the RegisterBounce() function builds the "msg" string from other variable strings and one of these strings may contain a % substitution string. This msg string is then passed to LogMsg but without an args tuple to satisfy the % substitution.
I'm no Python expert - I just started learning it a few weeks ago - but I'm trying to think of ways to debug this, or handle the situation more gracefully. I've been poking through the Python books I have and looking at the exception handling stuff. I've come up with the following simple idea for handling this in LogMsg(). Any opinions about whether this is a good idea, whether it will work, or whether there is a better way to approach this problem?
try: logf.write(msg % args + '\n') except: logf.write(msg + '\n')
-- Todd Pfaff \ Email: pfaff@mcmaster.ca Computing and Information Services \ Voice: (905) 525-9140 x22920 ABB 132 \ FAX: (905) 528-3773 McMaster University
Hamilton, Ontario, Canada L8S 4M1 \
Mailman-Users maillist - Mailman-Users@python.org http://www.python.org/mailman/listinfo/mailman-users
--
Todd Pfaff \ Email: pfaff@mcmaster.ca
Computing and Information Services \ Voice: (905) 525-9140 x22920
ABB 132 \ FAX: (905) 528-3773
McMaster University
Hamilton, Ontario, Canada L8S 4M1 \
"TP" == Todd Pfaff <pfaff@edge.cis.mcmaster.ca> writes:
TP> It seems that, in general, the use of LogMsg is inconsistent.
You're right about that. It would be a good thing to clean up the use of LogMsg. I usually do the substitution before passing it to LogMsg, but some of the older code does it the other way.
TP> Any opinions about whether this is
TP> a good idea, whether it will work, or whether there is a
TP> better way to approach this problem?
| try:
| logf.write(msg % args + '\n')
| except:
| logf.write(msg + '\n')
Just a point of Python style. It's almost never appropriate to use a "bare" except like this because it can mask unexpected exceptions. In this case using "except TypeError" would do the trick.
This is probably okay as a stopgap, but it would be better to make the use of LogMsg more consistent.
-Barry
On Fri, 3 Dec 1999, Barry A. Warsaw wrote:
TP> It seems that, in general, the use of LogMsg is inconsistent.
You're right about that. It would be a good thing to clean up the use of LogMsg. I usually do the substitution before passing it to LogMsg, but some of the older code does it the other way.
TP> Any opinions about whether this is TP> a good idea, whether it will work, or whether there is a TP> better way to approach this problem? | try: | logf.write(msg % args + '\n') | except: | logf.write(msg + '\n')
Just a point of Python style. It's almost never appropriate to use a "bare" except like this because it can mask unexpected exceptions. In this case using "except TypeError" would do the trick.
ok, thanks for the tip.
This is probably okay as a stopgap, but it would be better to make the use of LogMsg more consistent.
it wouldn't be a big job. there are only about 50 occurrences of LogMsg calls in all files under the Mailman python directory, and of these, only about 20 seem to have '%' substitution characters in the msg argument:
cd ~mailman/Mailman grep LogMsg * | grep '%' | wc
the ones that pass an arg tuple would simply have to be changed so that the ',' between the msg and args arguments is a '%' to do the substitutions before the call. then, remove the '%' substitution in LogMsg.
--
Todd Pfaff \ Email: pfaff@mcmaster.ca
Computing and Information Services \ Voice: (905) 525-9140 x22920
ABB 132 \ FAX: (905) 528-3773
McMaster University
Hamilton, Ontario, Canada L8S 4M1 \
participants (2)
-
Barry A. Warsaw
-
Todd Pfaff