Skip to content

python -m poplib fails with TypeError when printing messages #162073

Open

Description

@mPadovani74

Bug report

Running poplib as a script (python -m poplib / python Lib/poplib.py) crashes as soon as it tries to print a retrieved message.

retr() returns the message lines as bytes, but the __main__ block does print(' ' + line), concatenating str and bytes:

https://github.com/python/cpython/blob/2e14c838544/Lib/poplib.py#L466-L479

Reproducer (any POP3 server; I used a minimal local fake server):

$ python -m poplib 127.0.0.1 user password
b'+OK hi'
Message 1:
Traceback (most recent call last):
  File ".../poplib.py", line 477, in <module>
    print('   ' + line)
          ~~~~~~^~~~~~
TypeError: can only concatenate str (not "bytes") to str

Related problems in the same block:

  • getwelcome() also returns bytes, so the greeting is printed as b'+OK hi'.

  • Running without arguments gives a raw IndexError from sys.argv[1] instead of a usage message:

    $ python -m poplib
    IndexError: list index out of range
    
  • a.quit() is not reached if anything fails earlier, so the connection is not closed cleanly.

Expected: the script prints the welcome line and each message as text (e.g. decoded), and prints a usage message when arguments are missing.

This script is currently undocumented, see #93096 ("Decide the fate of undocumented script behavior of some modules"). I'm happy to send a minimal fix (decode the bytes, add a usage message) if the script is meant to stay, or to help remove it if that is the decision.

Tested on CPython main (3.16.0a2+dev, commit 2e14c83) on Linux.

CPython versions tested on:

3.16, CPython main branch

Operating systems tested on:

Linux

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions