Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ftplib.FTP.abort fails with TypeError on Python 3.x #56211

Closed
nneonneo mannequin opened this issue May 4, 2011 · 4 comments
Closed

ftplib.FTP.abort fails with TypeError on Python 3.x #56211

nneonneo mannequin opened this issue May 4, 2011 · 4 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@nneonneo
Copy link
Mannequin

nneonneo mannequin commented May 4, 2011

BPO 12002
Nosy @giampaolo, @ezio-melotti, @merwok
Files
  • ftplib.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/giampaolo'
    closed_at = <Date 2011-05-17.17:41:23.929>
    created_at = <Date 2011-05-04.21:45:11.998>
    labels = ['library', 'type-crash']
    title = 'ftplib.FTP.abort fails with TypeError on Python 3.x'
    updated_at = <Date 2011-05-17.17:41:23.928>
    user = 'https://bugs.python.org/nneonneo'

    bugs.python.org fields:

    activity = <Date 2011-05-17.17:41:23.928>
    actor = 'giampaolo.rodola'
    assignee = 'giampaolo.rodola'
    closed = True
    closed_date = <Date 2011-05-17.17:41:23.929>
    closer = 'giampaolo.rodola'
    components = ['Library (Lib)']
    creation = <Date 2011-05-04.21:45:11.998>
    creator = 'nneonneo'
    dependencies = []
    files = ['21925']
    hgrepos = []
    issue_num = 12002
    keywords = ['patch']
    message_count = 4.0
    messages = ['135158', '135329', '135474', '135489']
    nosy_count = 5.0
    nosy_names = ['nneonneo', 'giampaolo.rodola', 'ezio.melotti', 'eric.araujo', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue12002'
    versions = ['Python 3.1', 'Python 3.2', 'Python 3.3']

    @nneonneo
    Copy link
    Mannequin Author

    nneonneo mannequin commented May 4, 2011

    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)

    @nneonneo nneonneo mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels May 4, 2011
    @giampaolo giampaolo self-assigned this May 5, 2011
    @merwok
    Copy link
    Member

    merwok commented May 6, 2011

    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 :)

    @giampaolo
    Copy link
    Contributor

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 7, 2011

    New changeset 31220cd936d2 by Giampaolo Rodola' in branch '3.1':
    bpo-12002 - ftplib's abort() method raises TypeError
    http://hg.python.org/cpython/rev/31220cd936d2

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants