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 <[email protected]>
<http://bugs.python.org/issue25933>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com