Home > Software engineering >  Is there any way to remove the b'' from decoded base64 output?
Is there any way to remove the b'' from decoded base64 output?

Time:01-08

When i run

import base64

a = "aHR0cHM6Ly9kaXNjb3JkLmNvbS9hcGkvd2ViaG9va3MvMTA2MTQ2NzIxNDI2MTI2MDMwOC9wNklOLWgzVkRGSEo1UVIyNDVSXy1NUFlWZ2xfU2tRZ3RUemVPMUN2SGlUZlBSMEExSjhOQUdHVmt0NU1sZzhrYXVkRg=="
hook = base64.b64decode(a)

print(hook)

It returns:

b'https://discord.com/api/webhooks/1061467214261260308/p6IN-h3VDFHJ5QR245R_-MPYVgl_SkQgtTzeO1CvHiTfPR0A1J8NAGGVkt5Mlg8kaudF'

But i want it to only return https://discord.com/api/webhooks/1061467214261260308/p6IN-h3VDFHJ5QR245R_-MPYVgl_SkQgtTzeO1CvHiTfPR0A1J8NAGGVkt5Mlg8kaudF not the b''. Is there anyway to fix the problem? I know it says it because the type is byte.

CodePudding user response:

That's a bytes value that should be decoded to a str value:

>>> print(hook.decode())
https://discord.com/api/webhooks/1061467214261260308/p6IN-h3VDFHJ5QR245R_-MPYVgl_SkQgtTzeO1CvHiTfPR0A1J8NAGGVkt5Mlg8kaudF

Base64 is usually used to encode arbitrary binary data as ASCII text, which is why b64decode returns a bytes value. In this case, though, the "binary" data is itself just ASCII-encoded (or possibly UTF-8-encoded) text.

  • Related