python base64 字符串解码
我有一个应该是用UCS-2编码的xml文档,经过一些调整后,我成功地用minidom构建了一个DOM。
问题是,我应该有一些数据是用base64编码的。我知道:
AME= (or \x00A\x00M\x00E\x00=) is base64 code for Á
我该如何解码呢?
http://www.fileformat.info/info/unicode/char/00c1/index.htm 显示字符Á的unicode表示是:u"\u00C1",在UTF-16中是:0x00C1
base64.b64decode('AME=').decode('UTF-16')
显示
u'\uc100'
作为这个字符的unicode表示,但看起来像是字节顺序被调换了。
有没有人知道怎么解码呢?
1 个回答
17
看看这个
>>> import base64
>>> base64.b64decode('AME=').decode('UTF-16')
u'\uc100'
>>> base64.b64decode('AME=').decode('UTF-16LE')
u'\uc100'
>>> base64.b64decode('AME=').decode('UTF-16BE')
u'\xc1'
也许你是在找大端解码的方法?