Odd/Weird errors with FTPLib
python at mrabarnett.plus.com
Mon Sep 14 00:47:05 CEST 2009
> On 13 Sep, 22:41, Chris Rebert <c... at rebertia.com> wrote:
>> On Sun, Sep 13, 2009 at 2:34 PM, Bakes <ba... at ymail.com> wrote:
>>> I am using a simple python script to download my logfiles. This is on
>>> a while loop, the logfile grows rapidly, so it is necessary for python
>>> to start downloading the new script as soon as it has finished the
>>> It works fine (for about 20 minutes), then crashes. I have removed a
>>> couple of excepts, and have narrowed the error down to a 'error_perm:
>>> 550 logfile.log: The data is invalid.' error.
>>> Does anyone know what the problem might be regarding this, and what I
>>> might do to fix it?
>> Including an actual code snippet and the full error traceback would help a lot.
>> According tohttp://en.wikipedia.org/wiki/List_of_FTP_server_return_codes,
>> error code 550 translates to:
>> "Requested action not taken. File unavailable (e.g., file not found,
>> no access)."
>> Does the logfile get rotated or something, thus causing it to briefly not exist?
>> It might also help if you explain how your logfile system works.
> It's a cod4 gameserver logfile, being downloaded for a python bot to
> The logfile is downloaded using this try/except while loop.
> while True:
> if ftp == False:
> self.debug('FTP connection not active, attempting to (re)connect')
> ftp = self.ftpconnect()
> ftp.retrbinary('RETR ' + os.path.basename(self.ftpconfig ['path']), handleDownload, rest=size)
> if self.console._paused:
> print error
> self.debug('Lost connection to server, pausing until updated properly, Sleeping 10 seconds')
> self.debug('FTP Connection Closed')
> self.debug('FTP does not appear to be open, so not closed')
> ftp = False
> I can only assume that occasionally, the logfile is being written to
> by the gameserver at the same time that it's downloading.
> If this was the case, do you think a try: download except: sleep
> 900msec then download loop would work?
Bare excepts are almost always a bad idea because they'll catch _all_
exceptions, both those you expect could happen and those you don't.
Catch only those you expect.
For example, if the file 'games_mp.log' doesn't exist then
os.path.getsize('games_mp.log') will raise an exception, and if you
forgot to import the os module then that will raise a NameError
Anyway, I can't see how you leave the loop; I'd expect something like a
And as a matter of style, I'd prefer None to False to indicate when
there's no FTP connection (and "if not ftp" instead of "if ftp ==
More information about the Python-list