<br>Some things to consider:<br><br>1) You might see if there's something about the size of the message - is it bigger after collecting data all night?  Is google disconnecting after a maximum amount of data is transferred?<br>
<br>2) You might try sending a tiny test message at the beginning, just to yourself, and seeing if that has the problem<br><br>3) You might try running your script under a system call tracer: <a href="http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html">http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html</a> - and inspecting the list of syscalls and their return codes near when the process terminates<br>
<br>4) I get disconnects from gmail once in a while too, especially when downloading a large list of new message headers; I've been just coding around it by making my code idempotent and otherwise restartable.  This seems to happen with both 2.x and 3.x, so I assume it's not really related to the Python version, but I suppose I should try it on PyPy or Jython someday.  Note that the error message in 3.x was better than in 2.x.<br>
<br>HTH<br><br><div class="gmail_quote">On Wed, Aug 3, 2011 at 2:46 PM, Astley Le Jasper <span dir="ltr"><<a href="mailto:astley.lejasper@gmail.com">astley.lejasper@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I have a laptop that wakes up and then runs a script that collects<br>
info and sends an email with a spreadsheet (zipped and about 350KB)<br>
report to a number of people. However, every time I get the following<br>
error:<br>
<br>
<br>
File "/usr/lib/python2.7/smtplib.py", line 343, in getreply<br>
    raise SMTPServerDisconnected("Connection unexpectedly closed")<br>
<br>
<br>
- When I check the laptop and manually run the function that sends the<br>
email and report, it works fine. I have never been able to replicate<br>
the error when doing it manually.<br>
- It can't be a problem with Gmail at that time in the morning or my<br>
connection, because the script also sends me a copy of the log file<br>
straight after, and that works.<br>
- The same code has been working for years, it just that I have<br>
recently rebuilt the machine so now it is using Python 2.7. I have<br>
also change the references to use absolute file references, rather<br>
than relative. I also have changed the code to run as root.<br>
- I've checked the smtp debug report and everything seems ok. I just<br>
never get the confirmation code (250) to say that it's completed.<br>
- Even stranger ... it ran ok once. But I didn't change a thing and<br>
the next day it wouldn't work.<br>
<br>
The only thing I can think of is that when the file is transferred to<br>
the reports directory, it somehow isn't been released quickly enough<br>
and perhaps this is tripping up SMTP. But ... this is a bit of a guess<br>
given I've tried to exhaust all the other options.<br>
<br>
Any ideas?<br>
<font color="#888888"><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>