[New-bugs-announce] [issue10970] "string".encode('base64') is not the same as base64.b64encode("string")

Mahmoud Abdelkader report at bugs.python.org
Fri Jan 21 07:25:16 CET 2011

New submission from Mahmoud Abdelkader <mabdelkader at gmail.com>:

Given a string, encoding it with .encode('base64') is not the same as using base64's b64encode function. I think this is very unclear and unintuitive. 

Here's some example code to demonstrate the problem. Before I attempt to submit a patch, is this done for legacy reasons? Are there any reasons to use one over the other?

import hmac
import hashlib
import base64

signature = hmac.new('secret', 'url', hashlib.sha512).digest()
assert signature.encode('base64') == base64.b64encode(signature)

components: Library (Lib)
messages: 126696
nosy: mahmoudimus
priority: normal
severity: normal
status: open
title: "string".encode('base64') is not the same as base64.b64encode("string")
versions: Python 2.5, Python 2.6, Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list