Getting Eoferror Along With Exceptions When Using Ftplib
Solution 1:
The servers are sending EOF
to tell you that they've terminated the connection.
You should treat this no differently than any other disconnection event, except that obviously you need to handle it with except EOFError
.
See the source, from http://svn.python.org/view/python/trunk/Lib/ftplib.py?view=markup
# Internal: return one line from the server, stripping CRLF.# Raise EOFError if the connection is closed182defgetline(self):
183 line = self.file.readline()
184if self.debugging > 1:
185print'*get*', self.sanitize(line)
186ifnot line: raise EOFError
187if line[-2:] == CRLF: line = line[:-2]
188elif line[-1:] in CRLF: line = line[:-1]
189return line
EOFError is only raised when readline()
on the connection returns a blank line, which the comment indicates is a disconnection event.
Edit in re your comment:
The server doesn't send an empty line. readline()
returns everything up to the next \n
or \r
or \r\n
or all of the abouve depending on how it's configured. In this case, there is nothing to read because the end of the file has been reached. This causes readline()
to return a blank line, it doesn't mean a blank line has been read. If a blank line had been read, readline()
would return the character that ended the line (\n
or \r
or \n\r
).
If you don't get the exception when using FTPUtil, that is because it handles it internally.
Post a Comment for "Getting Eoferror Along With Exceptions When Using Ftplib"