Message 76223 - Python tracker (original) (raw)

"This module provides data encoding and decoding as specified in RFC 3548. This standard defines the Base16, Base32, and Base64 algorithms for encoding and decoding arbitrary binary strings into text strings that can be safely sent by email, used as parts of URLs, or included as part of an HTTP POST request. "

In other words, arbitrary 8-bit byte strings <=> 'safe' byte strings You have to encode unicode to bytes first, as you did. Str works because you only have ascii chars and str uses the ascii encoder by default. The bytes() constructor has no default and 'ascii' must be supplied

The error message is correct even if backwards. Unicode.translate requires a unicode mapping, whereas b64decode supplies a bytes mapping because it requires bytes.

3.0 added an earlier type check, so the same code gives TypeError: expected bytes, not str

I believe there was an explicit decision to leave low-level wire- protocol byte functions as bytes/bytearray only.

The 3.0 manual needs updating in this respect, but I will start another issue for that.