Message256927
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 |
|
Date |
User |
Action |
Args |
2015-12-23 19:38:46 | Sam Adams | set | recipients:
+ Sam Adams |
2015-12-23 19:38:46 | Sam Adams | set | messageid: <1450899526.91.0.95420964187.issue25933@psf.upfronthosting.co.za> |
2015-12-23 19:38:46 | Sam Adams | link | issue25933 messages |
2015-12-23 19:38:46 | Sam Adams | create | |
|