Thursday, October 10, 2013

base64 in WLST

if you try using base64 in WLST:
import base64
encoded = base64.b64encode('data to be encoded')


you get a:

AttributeError: 'module' object has no attribute 'b64encode'


reason being that there is:
/usr/lib64/python2.4/base64.py
and
/opt/oracle/fmw11_1_1_5/oracle_common/util/jython/Lib/base64.py

b64decode does:
import binascii
binascii.a2b_base64(s)
b64encode does:
import binascii
binascii.b2a_base64(s)[:-1]
So basically:
import binascii
s='string to encode'
encoded = binascii.b2a_base64(s)[:-1]
print binascii.a2b_base64(encoded)
string to encode
print encoded
c3RyaW5nIHRvIGVuY29kZQ==



No comments: