[New-bugs-announce] [issue3613] base64.encodestring does not actually accept strings

Dmitry Dvoinikov report at bugs.python.org
Wed Aug 20 08:00:34 CEST 2008

New submission from Dmitry Dvoinikov <dmitry at targeted.org>:

This quote from base64.py:

bytes_types = (bytes, bytearray)  # Types acceptable as binary data
def encodestring(s):
    """Encode a string into multiple lines of base-64 data.

    Argument and return value are bytes.
    if not isinstance(s, bytes_types):
        raise TypeError("expected bytes, not %s" % s.__class__.__name__)

shows that encodestring method won't accept str for an argument, only
bytes. Perhaps this is by design, but then wouldn't it make sense to
change the name of the method ?

Anyway, this behavior clashes in (the least I know) xmlrpc.client, line
1168 when basic authentication is present:

auth = base64.encodestring(urllib.parse.unquote(auth))

because unquote() returns str, not bytes.

components: Library (Lib)
messages: 71513
nosy: ddvoinikov
severity: normal
status: open
title: base64.encodestring does not actually accept strings
type: behavior
versions: Python 3.0

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list