0

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.

DeVYuvi
  • 13
  • 5
  • `b'` is only used when printing the *representation*, and the bytes are still `https://discord.com/...g8kaudF`. Are you looking perhaps to *convert* those bytes to a string of characters? – nanofarad Jan 08 '23 at 02:33
  • I just want https://discord.com/api/webhooks/1061467214261260308/p6IN-h3VDFHJ5QR245R_-MPYVgl_SkQgtTzeO1CvHiTfPR0A1J8NAGGVkt5Mlg8kaudF to not be readable, so i thought i would convert it into a base64 then decode when i need it. – DeVYuvi Jan 08 '23 at 02:35
  • `hook.decode("ascii")` – Yarin_007 Jan 08 '23 at 02:35
  • 1
    @DeVYuvi Encoding it doesn't make it *un*readable; it's instantly recognizable as base64, and if it contains info that must be kept secret (not sure if that applies to the discord webhook or token), then it'll be quite easy to find. – nanofarad Jan 08 '23 at 02:36
  • @DeVYuvi, what are you trying to accomplish? what's the end goal? – Yarin_007 Jan 08 '23 at 02:37
  • I'm trying to make a program that sends a message to the webhook without the person running it knowing there is a webhook, however not using for any malicious purposes. – DeVYuvi Jan 08 '23 at 02:39

1 Answers1

1

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.

chepner
  • 497,756
  • 71
  • 530
  • 681