Re: [Zope] error with simple python script loop

2006-11-27 Thread Chris Withers

Christian Steinhauer wrote:

http://www.blunck.se/iehttpheaders/iehttpheaders.html



What a nice tool. Now more debugging with some interesting results. 


###
for i in range(2):
  context.MailHost.send('bodytext', [EMAIL PROTECTED], [EMAIL PROTECTED],
'subj'+str(i))
###
This script produces: HTTP/1.1 204 No Content


Moral of the story: if you want sane things to happen, make sure your 
script returns a string output.


Otherwise you risk tickling some of the more arcane features of Zope 
2's publisher. They include no content responses if you return None 
and even weirder things if you return a two-element tuple.


This isn't a bug, you're doing something silly, stop doing it ;-)

cheers,

Chris

--
Simplistix - Content Management, Zope  Python Consulting
   - http://www.simplistix.co.uk
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


RE: [Zope] error with simple python script loop

2006-11-27 Thread Christian Steinhauer
 
   context.MailHost.send('bodytext', [EMAIL PROTECTED],
[EMAIL PROTECTED],
 'subj'+str(i))
 ###
 This script produces: HTTP/1.1 204 No Content

Moral of the story: if you want sane things to happen, make sure your 
script returns a string output.

Otherwise you risk tickling some of the more arcane features of Zope 
2's publisher. They include no content
responses if you return None and even weirder things if you return a 
two-element tuple.

This isn't a bug, you're doing something silly, stop doing it ;-)

Here i must add that it is an test script for the list only, the real script
which has produce the error is bigger and it has an output of string. But
the part which is sending the mail has produce the double emails, so i debug
this part. 

Here is a bit of the original script, so tell me again why i get the error,
because it has an string output. 

###
recp_list = []
request.set('Query','SQL SELECT')

for i in context.sql_query():
  mMsg = 'test'
  mTo = str(i[m_to])
  mFrom = str(i[m_from])
  mSubj = str(i[l_subject])
  context.MailHost.send(mMsg, mTo, mFrom, mSubj)
  recp_list.append(i[u_email])

recp_output = str(recp_list)
mRet = 'E-Mails send to:br' + recp_output + 'brbr'
return mRet
###

This script is the part of the devil ;) It has produce the double emails, i
have cut some lines codes to get it faster to understand. 

- cs

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-27 Thread Maciej Wisniowski
 This script is the part of the devil ;) It has produce the double emails, i
 have cut some lines codes to get it faster to understand. 
Have you tried what I posted before? I mean try to add to your script:
container.REQUEST.RESPONSE.setHeader('content-type', 'text/html')

I'm curious if this changes anything.

-- 
Maciej Wisniowski
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-27 Thread Dieter Maurer
Chris Withers wrote at 2006-11-27 16:16 +:
 ...
Moral of the story: if you want sane things to happen, make sure your 
script returns a string output.

In fact, an empty string would result in the same behaviour.

Thus, the moral should be: make your your script does not return
a Python false value. As returning nothing, means returning None
which is a Python false value, this implies, return something.



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


RE: [Zope] error with simple python script loop

2006-11-27 Thread Christian Steinhauer

Have you tried what I posted before? I mean try to add to your script:
container.REQUEST.RESPONSE.setHeader('content-type', 'text/html')

I'm curious if this changes anything.

yes i test this and then the header is everytime 200 OK - so no problem. But
i test this only with my 2 lines of code test script, not with the big
application. Now the IE7 does it better i think, but i must test this next
days. 

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-25 Thread Maciej Wisniowski
 The third script has no output on the screen too but works fine and
 gives HTTP Code 200 back. Can you tell me why he do this?
This is because of call to ZPT in your third script. ZPT call sets
RESPONSE HTTP headers with content/type='text/html'. Try this:

for i in range(2):
  context.MailHost.send('bodytext', [EMAIL PROTECTED], [EMAIL PROTECTED],
 'subj'+str(i))
container.REQUEST.RESPONSE.setHeader('content-type', 'text/html')

And you should get 200 OK status too.

You may compare these results from IE with results from Firefox. There
is LiveHttpHeaders plugin for FF that will show you similiar output as
above (but in FF environment).

In general seems that it is a IE bug.

-- 
Maciej Wisniowski

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] error with simple python script loop

2006-11-24 Thread Christian Steinhauer
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', [EMAIL PROTECTED],
[EMAIL PROTECTED], 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', [EMAIL PROTECTED],
[EMAIL PROTECTED], 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
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Chris Withers

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', [EMAIL PROTECTED],
[EMAIL PROTECTED], 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
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Maciej Wisniowski

 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
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Christian Steinhauer

 

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.

There is no traceback, i got no error - thats why i have post it into
bug tracker. I spoke to many people but no one can tell me why it
occured. The most said that it must be a bug in zope or python. 

@Maciej: I call the script simple over url or the test button - it is
a script for testing only - it is not called by any other script 
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



- --On 24. November 2006 13:39:07 +0100 Christian Steinhauer 
[EMAIL PROTECTED] wrote:




 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.

 There is no traceback, i got no error - thats why i have post it into
 bug tracker. I spoke to many people but no one can tell me why it
 occured. The most said that it must be a bug in zope or python.



Then it is time to address the issue on your own by taking pdb
and making further investigations.

- -aj
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (Darwin)

iD8DBQFFZuhaCJIWIbr9KYwRAhHmAJ9Swgqa2vsSLaSkO7KgS/GxOvot6ACgk5ms
8iDCMq7WZf3n4gq6qkEe/MQ=
=Gmjt
-END PGP SIGNATURE-

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Jonathan
- Original Message - 
From: Christian Steinhauer [EMAIL PROTECTED]

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', [EMAIL PROTECTED],
[EMAIL PROTECTED], 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', [EMAIL PROTECTED],
[EMAIL PROTECTED], 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', [EMAIL PROTECTED], 
[EMAIL PROTECTED], 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



___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Christian Steinhauer
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', [EMAIL PROTECTED], 
[EMAIL PROTECTED], 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.

Hi Jonathan, thanks for taking care of the problem. I have done the self test 
you do with the list. But everytime when something is written at last line, 
example return 'eof' (My example in the topic) the error did not occured - so 
the list gives me 2 and i will get 2 emails.

The error only occured when nothing is written under the loop. 

I have 2 real separeted dedicated servers, one with zope 2.6.4 and one with 
2.10 - the problem occured on both servers.
So i used the zope product MailDropHost too and get the self error on both 
server. With MailDropHost i can see a spooler - thats nice - but in the spooler 
i see 4 emails. So the Operating System or Exim get 4 Mails from Zope/Python. 
I´m using Debian Linux. 
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Jonathan


- Original Message - 
From: Christian Steinhauer [EMAIL PROTECTED]

To: Jonathan [EMAIL PROTECTED]; zope@zope.org
Sent: Friday, November 24, 2006 8:19 AM
Subject: Re: [Zope] error with simple python script loop



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', [EMAIL PROTECTED],
[EMAIL PROTECTED], 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.


Hi Jonathan, thanks for taking care of the problem. I have done the self 
test you do with the list. But everytime when something is written at last 
line, example return 'eof' (My example in the topic) the error did not 
occured - so the list gives me 2 and i will get 2 emails.


The error only occured when nothing is written under the loop.

I have 2 real separeted dedicated servers, one with zope 2.6.4 and one 
with 2.10 - the problem occured on both servers.
So i used the zope product MailDropHost too and get the self error on 
both server. With MailDropHost i can see a spooler - thats nice - but in 
the spooler i see 4 emails. So the Operating System or Exim get 4 Mails 
from Zope/Python.

I´m using Debian Linux.


I tried to reproduce your '4 iteration' problem on my Zope 2.9.2 
installation, but even by removing the 'return' statement I still got 2 loop 
iterations (and 2 emails).


I have never written a python script that did not have a 'return' statement. 
I don't know if it is mandatory or not. I usually use python scripts as 
subroutines/functions and I always have a return statement  (even if it is a 
bare return - ie. the return statement does not send back any data).


As Andreas suggested, if you want to track this down you are going to have 
to use a debugger like pdb.


Jonathan



___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


RE: [Zope] error with simple python script loop

2006-11-24 Thread Christian Steinhauer
I tried to reproduce your '4 iteration' problem on my Zope 2.9.2 
installation, but even by removing the 'return' statement I 
still got 2 loop 
iterations (and 2 emails).

I have never written a python script that did not have a 
'return' statement. 
I don't know if it is mandatory or not. I usually use python 
scripts as 
subroutines/functions and I always have a return statement  
(even if it is a 
bare return - ie. the return statement does not send back any data).

As Andreas suggested, if you want to track this down you are 
going to have 
to use a debugger like pdb.

I have test the script on my local windows python version with an print 
statement, and it works fine - everytime - so its only on zope. i cant use pdb 
on zope´s python script i think? 
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Maciej Wisniowski


 Hi Jonathan, thanks for taking care of the problem. I have done the self test 
 you do with the list. But everytime when something is written at last line, 
 example return 'eof' (My example in the topic) the error did not occured - so 
 the list gives me 2 and i will get 2 emails.
   
So try without return, eg.:
1. create ZPT with id: 'counter'
2. edith 'counter' that it contains only '0'
3. Create Script (Python):
val = context.counter()
v = int(val)+1
context.counter.write(str(v))

and test this script with/without return.

Then see what value is in 'counter' ZPT.

I have always only +1 increment, and you?

-- 
Maciej Wisniowski
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] error with simple python script loop

2006-11-24 Thread Jens Vagelpohl

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


On 24 Nov 2006, at 14:38, Jonathan wrote:
I have never written a python script that did not have a 'return'  
statement. I don't know if it is mandatory or not. I usually use  
python scripts as subroutines/functions and I always have a return  
statement  (even if it is a bare return - ie. the return statement  
does not send back any data).


It is not necessary to put in your own return statement. They just  
return None if no return statement is present, which is the same for  
normal Python code.


jens



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (Darwin)

iD8DBQFFZwnJRAx5nvEhZLIRAhIiAJ9mNhtpO0bV6lo7i11hRtqjlhlXBwCfSATl
gsBBHxu8iQAj8j3YcBvW8CM=
=qyQh
-END PGP SIGNATURE-
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )