Reputation: 107
Am upgrading to py3 and have py2 compatible code which is now throwing an error of TypeError: must be str, not bytes
In the script its sending a shell echo command with an encoded string.
"echo \"" + base64.b64encode(b'Hello World') + "\" | base64 -d"
How can I modify the above to make it pass?
Thanks
Upvotes: 0
Views: 207
Reputation: 477
You could convert the strings to bytes as well and then decode them:
bytes_string = b"echo \"" + base64.b64encode(b'Hello World') + b"\" | base64 -d"
print(bytes_string.decode('utf-8'))
>>> echo "SGVsbG8gV29ybGQ=" | base64 -d
Upvotes: 1