How to Encode String Base64 on Python 3

811 views
Skip to first unread message

Aphirak Phothisa

unread,
Jan 17, 2020, 3:12:22 AM1/17/20
to robotframework-users
How to Encode String Base64 on Python 3 
in  Python 2.7 I use below this 
${encode_string}=    Encode String To Bytes    ${username}:${password}    Base64

Hélio Guilherme

unread,
Jan 17, 2020, 4:29:05 AM1/17/20
to robotframework-users
That is Robot Framework syntax and it is the same when using Python 2.7 or 3.x.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/CA%2Bqya7SvgLoPhC7vsf63zX5R2DpFFeubmN%2Br8YNMCQSzYO8Gew%40mail.gmail.com.

Aphirak Phothisa

unread,
Jan 17, 2020, 4:52:13 AM1/17/20
to heliox...@gmail.com, robotframework-users
image.png
I found the situation when I run the script on Python 2.7  it is a pass but Python 3 it got the error above.

Hélio Guilherme

unread,
Jan 17, 2020, 6:39:49 AM1/17/20
to robotframework-users
I confirm that it works on python 2.7 but not on python 3.7.
That looks like a bug, you should open on  https://github.com/robotframework/robotframework  

test_encode_bytes.robot

Adrien Vergnaud

unread,
Jan 18, 2020, 5:39:59 AM1/18/20
to robotframework-users
Hello,

you can use module codecs to do this.
I have same need. Convert hexa string into string base64.
Here an example:
b64_string = codecs.encode(codecs.decode(my_string_hexa, 'hex'), 'base64').decode()

Pekka Klärck

unread,
Jan 18, 2020, 5:46:00 AM1/18/20
to maico...@gmail.com, Hélio Guilherme, robotframework-users
Python 3 changed string encoding a bit and under the new scheme base64 just doesn't work. There's nothing our Encode String To Bytes keyword could do about it, but it ought to be fairly easy to implement new base64 encode/decode kws utilizing this module:

Reply all
Reply to author
Forward
0 new messages