[New-bugs-announce] [issue25933] Unhandled exception (TypeError) with ftplib in function retrbinary/retrlines causes inoperable behavior without crashing
Sam Adams
report at bugs.python.org
Wed Dec 23 14:38:46 EST 2015
New submission from Sam Adams:
Hello,
I believe that I found a bug in ftplib.py in version 3.3.6.
Whenever a user opens a file for writing in nonbinary mode and then proceeds to call the retrbinary function, or opens the file in binary mode and proceeds to call the retrlines fuction, then attempts to write to the file using the callback function, an unhandled TypeError exception is raised that does not cause the program to crash, but rather cause the last message from the server to not be "read" by the readline() function, thus causing cascading errors until the function readline() is called on its own or the connection with the server is reset.
Code to replicate:
from ftplib import FTP
ftp = FTP('your.server.here')
ftp.login()
fileTest = open('filename','w') <---- not binary
ftp.retrbinary('retr randomfilehere',fileTest.write)
Unhandled exception raised:
File "/usr/local/lib/python3.3/ftplib.py", line 434, in retrbinary
callback(data)
TypeError: must be str, not bytes
Likewise, if
ftp.retrlines('retr randomfilehere', fileTest.write)
is called when fileTest is opened for writing with binary option the following error is raised:
File "/usr/local/lib/python3.3/ftplib.py", line 464, in retrlines
callback(line)
TypeError: 'str' does not support the buffer interface
Calling ftp.getline() clears the error and resumes normal operation
Possible Solution:
add exception handling in lines 434/464 for TypeError
----------
components: Library (Lib)
messages: 256927
nosy: Sam Adams
priority: normal
severity: normal
status: open
title: Unhandled exception (TypeError) with ftplib in function retrbinary/retrlines causes inoperable behavior without crashing
versions: Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25933>
_______________________________________
More information about the New-bugs-announce
mailing list