This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ftplib.FTP.abort fails with TypeError on Python 3.x
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: giampaolo.rodola Nosy List: eric.araujo, ezio.melotti, giampaolo.rodola, nneonneo, python-dev
Priority: normal Keywords: patch

Created on 2011-05-04 21:45 by nneonneo, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ftplib.patch giampaolo.rodola, 2011-05-07 15:42 review
Messages (4)
msg135158 - (view) Author: Robert Xiao (nneonneo) * Date: 2011-05-04 21:45
On Python 3.2, calling abort() on an ftplib.FTP object will cause an exception:

>>> ftp = ftplib.FTP('localhost')
>>> ftp.abort()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/ftplib.py", line 246, in abort
    self.sock.sendall(line, MSG_OOB)
TypeError: 'str' does not support the buffer interface

The offending line, ftplib.py:246, should be replaced by
self.sock.sendall(line.encode(self.encoding), MSG_OOB)
msg135329 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-05-06 17:02
Thanks for the report.  If you would like to turn your suggestion into a diff file (see guidelines at http://docs.python.org/devguide) containing the code change and a test, you could get into the Misc/ACKS file and get eternal glory :)
msg135474 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-05-07 15:42
This is a nasty one and mainly it's the reason why there are no tests for abort() method.
In FTP, ABOR command is supposed to be sent as OOB (out-of-band) "urgent" data and the dummy FTP server we're using for the funcional tests must handle this appopriately.

In practical terms this means that when the client calls self.sock.sendall(line, MSG_OOB) the server is supposed to call socket.recv(1024, MSG_OOB).
Since our server uses asyncore this becomes quite twisted to handle.
This can be avoided by setting SO_OOBINLINE which tells the server to handle the urgent data inline meaning that both plain and urgent data can be received with a normal sock.recv(1024) call.

The patch in attachment does this and also fixes FTP_TLS.abort() which is not able to accept the extra MSG_OOB flag argument.

There's a side note: on certain platforms SO_OOBINLINE has no effect, resulting in asyncore's handle_expt method being called, see:
http://code.google.com/p/pyftpdlib/source/browse/trunk/pyftpdlib/ftpserver.py#2064
I haven't handled this case in my patch because I'm not sure what platforms are broken.
I'd say we can commit this patch as-is, wait for the buildbots to turn red and then disable the test for those platforms afterwards.
msg135489 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-07 17:35
New changeset 31220cd936d2 by Giampaolo Rodola' in branch '3.1':
#12002 - ftplib's abort() method raises TypeError
http://hg.python.org/cpython/rev/31220cd936d2
History
Date User Action Args
2022-04-11 14:57:16adminsetgithub: 56211
2011-05-17 17:41:23giampaolo.rodolasetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2011-05-07 17:35:49python-devsetnosy: + python-dev
messages: + msg135489
2011-05-07 15:42:42giampaolo.rodolasetfiles: + ftplib.patch
keywords: + patch
messages: + msg135474
2011-05-06 17:02:27eric.araujosetversions: - Python 3.4
nosy: + eric.araujo

messages: + msg135329

stage: needs patch
2011-05-05 12:08:34giampaolo.rodolasetassignee: giampaolo.rodola
2011-05-05 11:13:31ezio.melottisetnosy: + giampaolo.rodola, ezio.melotti
2011-05-04 21:45:12nneonneocreate