error with simple python script loop
I have an problem with this little script. The script is in the zope file structure and it is an -Script (Python)- The script should send 2 emails over the mailhost, but it sends 4 emails. I have test this with maildrophost product too, same problem. I have test it on Zope 2.10.0 and Zope 2.64. The problem is the same - everytime. This script produce the error: #### start #### for i in range(2): subj = str(i) + ' range python' context.MailHost.send('range test with python', "rec@mail.com", "sender@mail.com", subj) #### end #### This script produce no error: #### start #### for i in range(2): subj = str(i) + ' range python' context.MailHost.send('range test with python', "rec@mail.com", "sender@mail.com", subj) return 'eof' #### end #### So if i make a return (not in the loop) the script works fine. Can anybody tell me why? It feels like that there are any spaces in the script and zope/python did not work correctly when there is no other procedure after the for loop. I dont understand why he calls the loop two times and produce 4 emails. There is no transactional error in the error_log. thx for help
Christian Steinhauer wrote:
This script produce the error: #### start #### for i in range(2): subj = str(i) + ' range python' context.MailHost.send('range test with python', "rec@mail.com", "sender@mail.com", subj) #### end ####
As I said in the tracker, no one can help you if you don't actually give us the full traceback and exception that you got. Chris
-- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
The script should send 2 emails over the mailhost, but it sends 4 emails. I have test this with maildrophost product too, same problem. I have test it on Zope 2.10.0 and Zope 2.64. The problem is the same - everytime.
How do you call this script? Directly (via URL)? Or it is called by other script? -- Maciej Wisniowski
----- Original Message ----- From: "Christian Steinhauer" <steinhauer@know-it.net> To: <zope@zope.org> Sent: Friday, November 24, 2006 7:12 AM Subject: [Zope] error with simple python script loop
I have an problem with this little script. The script is in the zope file structure and it is an -Script (Python)-
The script should send 2 emails over the mailhost, but it sends 4 emails. I have test this with maildrophost product too, same problem. I have test it on Zope 2.10.0 and Zope 2.64. The problem is the same - everytime.
This script produce the error: #### start #### for i in range(2): subj = str(i) + ' range python' context.MailHost.send('range test with python', "rec@mail.com", "sender@mail.com", subj) #### end ####
This script produce no error: #### start #### for i in range(2): subj = str(i) + ' range python' context.MailHost.send('range test with python', "rec@mail.com", "sender@mail.com", subj) return 'eof' #### end ####
So if i make a return (not in the loop) the script works fine. Can anybody tell me why? It feels like that there are any spaces in the script and zope/python did not work correctly when there is no other procedure after the for loop. I dont understand why he calls the loop two times and produce 4 emails. There is no transactional error in the error_log.
I just cut and pasted your code into a python script on my Zope installation (2.9.2) and it worked as expected (ie. 2 emails sent). So something is pooched in your installation. A quick way to check to see if your script is looping more than you expect is to do something like: loopCheck = [] for i in range(2): subj = str(i) + ' range python' context.MailHost.send('range test with python', "rec@mail.com", "sender@mail.com", subj) loopCheck.append(subj) return loopCheck If you are getting only 2 iterations of the loop (as it should be), then something is wrong with your MailHost (if this is the case try deleting it and re-adding it). Another test: place a local copy of MailHost in the same folder as your script and see what happens. hth Jonathan
Christian Steinhauer wrote at 2006-11-24 13:12 +0100:
I have an problem with this little script. The script is in the zope file structure and it is an -Script (Python)-
The script should send 2 emails over the mailhost, but it sends 4 emails. I have test this with maildrophost product too, same problem. I have test it on Zope 2.10.0 and Zope 2.64. The problem is the same - everytime.
This script produce the error: #### start #### for i in range(2): subj = str(i) + ' range python' context.MailHost.send('range test with python', "rec@mail.com", "sender@mail.com", subj) #### end ####
This script produce no error: #### start #### for i in range(2): subj = str(i) + ' range python' context.MailHost.send('range test with python', "rec@mail.com", "sender@mail.com", subj) return 'eof' #### end ####
Do you call your script directly from a browser? In this case, a browser problem may be the reason for your observation. The first variant (lacking a return) will effectively return "None", a Python false value. The ZPublisher will turn any Python false value into a 205 response ("no content"). Almost all browsers, I have met so far, handle 205 responses in a buggy way. Maybe, your browser will repeat the call... I have seen several problem reports in mailing lists complaining that IE under some (still obscur) circumstances repeat a request. You should look into your "Z2.log" file (you may need to enable it in the Zope configuration file) and verify whether your requests are doubled.... -- Dieter
participants (5)
-
Chris Withers -
Christian Steinhauer -
Dieter Maurer -
Jonathan -
Maciej Wisniowski