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.

Answer from chepner on Stack Overflow
Top answer
1 of 9
233

decode the bytes to produce a str:

b = b'1234'
print(b.decode('utf-8'))  # '1234'
2 of 9
27

The object you are printing is not a string, but rather a bytes object as a byte literal.

Consider creating a byte object by typing a byte literal (literally defining a byte object without actually using a byte object e.g. by typing b'') and converting it into a string object encoded in utf-8. (Note that converting here means decoding)

byte_object= b"test" # byte object by literally typing characters
print(byte_object) # Prints b'test'
print(byte_object.decode('utf8')) # Prints "test" without quotations

We simply applied the .decode(utf8) function.


String literals are described by the following lexical definitions:

https://docs.python.org/3.3/reference/lexical_analysis.html#string-and-bytes-literals

stringliteral   ::=  stringprefix
stringprefix    ::=  "r" | "u" | "R" | "U"
shortstring     ::=  "'" shortstringitem* "'" | '"' shortstringitem* '"'
longstring      ::=  "'''" longstringitem* "'''" | '"""' longstringitem* '"""'
shortstringitem ::=  shortstringchar | stringescapeseq
longstringitem  ::=  longstringchar | stringescapeseq
shortstringchar ::=  <any source character except "\" or newline or the quote>
longstringchar  ::=  <any source character except "\">
stringescapeseq ::=  "\" <any source character>

bytesliteral   ::=  bytesprefix(shortbytes | longbytes)
bytesprefix    ::=  "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"
shortbytes     ::=  "'" shortbytesitem* "'" | '"' shortbytesitem* '"'
longbytes      ::=  "'''" longbytesitem* "'''" | '"""' longbytesitem* '"""'
shortbytesitem ::=  shortbyteschar | bytesescapeseq
longbytesitem  ::=  longbyteschar | bytesescapeseq
shortbyteschar ::=  <any ASCII character except "\" or newline or the quote>
longbyteschar  ::=  <any ASCII character except "\">
bytesescapeseq ::=  "\" <any ASCII character>
Discussions

Remove 'b' character do in front of a string literal in Python 3 - Stack Overflow
I am new in python programming and i am a bit confused. I try to get the bytes from a string to hash and encrypt but i got b'...' b character in front of string just like the below example. Is an... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Remove trailing "=" when base64 encoding - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I am noticing that whenever I base64 encode a string, a "=" is appended at the end. Can I remove this character and then reliably decode it later by adding it back, or is this dangerous? More on stackoverflow.com
๐ŸŒ stackoverflow.com
sed - Remove all base64 blocks from a file - Unix & Linux Stack Exchange
I am in the process of trying to upload around 20 years worth of Usenet archives to archive.org but my first batch got reject because some of the archives contained trojans that are encoded in base... More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
February 11, 2022
How to Decode base64 string value using uipath?
Hi Team , I have python encoded base64 value while trying to decode with some python/C# script but not getting the exact value .Can someone please help on this. Encoded value:LDwHASBuLmEHGgBuBGF0XwUmMAUCMAl0TQk2IFcsIDE1ICgoAAQJIAcPUDh1bTIiQDZhRFsGIG1wXQA+PHN0eWxlPiwiMiIAAzB+cDNSVhEiOVMAPGJ... More on forum.uipath.com
๐ŸŒ forum.uipath.com
12
0
June 9, 2023

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.

Answer from chepner on Stack Overflow
๐ŸŒ
Base64 Decode
base64decode.org
Base64 Decode and Encode - Online
Please note that this file is removed from our system immediately after the first download attempt or 15 minutes of inactivity. ... Bonus tip: Bookmark us! Meet Base64 Decode and Encode, a simple online tool that does exactly what it says: decodes from Base64 encoding as well as encodes into it quickly and easily.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Base64
Base64 - Wikipedia
March 6, 2026 - bGlnaHQgdw== is decoded, we convert each character (except the trailing occurrences of =) into their corresponding 6-bit representation, and then discard 2 trailing bits for the first = and another 2 trailing bits for the other =. In this instance, we would get 6 bits from the d, and another 6 bits from the w for a bit string of length 12, but since we remove 2 bits for each = (for a total of 4 bits), the dw== ends up producing 8 bits (1 byte) when decoded. Use of the padding character in encoded text is not essential for decoding. The number of missing bytes can be inferred from the length of the encoded text. In some variants, the padding character is mandatory, while for others it is not used. Notably, when concatenating Base64 encoded strings, then use of padding characters is required.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ base64.html
base64 โ€” Base16, Base32, Base64, Base85 Data Encodings
If validate is False (the default), characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check. If validate is True, these non-alphabet characters in the input result in a binascii.Error. For more information about the strict base64 check, see binascii.a2b_base64() May assert or raise a ValueError if the length of altchars is not 2. ... Encode bytes-like object s using the standard Base64 alphabet and return the encoded bytes. ... Decode bytes-like object or ASCII string s using the standard Base64 alphabet and return the decoded bytes.
๐ŸŒ
Base64Encode.org
base64encode.org โ€บ enc โ€บ remove
Base64 Encoding of "remove" - Online
Encode remove to Base64 format with various advanced options. Our site has an easy to use online tool to convert your data.
Find elsewhere
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.base64-decode.php
PHP: base64_decode - Manual
Defaults to dropping the padding on encode since it's not required for decoding, and keeps the URL free of % encodings. <?php function base64url_encode($data, $pad = null) { $data = str_replace(array('+', '/'), array('-', '_'), base64_encode($data)); if (!$pad) { $data = rtrim($data, '='); } return $data; } function base64url_decode($data) { return base64_decode(str_replace(array('-', '_'), array('+', '/'), $data)); }
๐ŸŒ
YouTube
youtube.com โ€บ codinggpt
python remove b prefix - YouTube
Download this code from https://codegive.com In Python, a bytes literal is represented with a 'b' prefix, indicating that the following sequence of character...
Published ย  December 23, 2023
Views ย  112
๐ŸŒ
Python Pool
pythonpool.com โ€บ home โ€บ blog โ€บ 5 ways to convert bytes to string in python
5 Ways to Convert bytes to string in Python - Python Pool
May 3, 2023 - The function is used to convert from the encoding scheme, in which the argument string is encoded to the desired encoding scheme, through which the b prefix gets removed. Let us look at the example for understanding the concept in detail. str_object = b'Python Pool' print(str_object) str_object = str_object.decode() print(str_object) ... It is a sequence of Unicode characters (encoded in UTF -16 or UTF-32 and entirely depends on Pythonโ€™s compilation). It is used to represent an integer between 0 and 255, and we can denote it as โ€˜bโ€™ or โ€˜B.โ€™ ยท We can change bytes to a base64 string and vice versa with the help of base64 library.
๐ŸŒ
Base64.Guru
base64.guru โ€บ tools โ€บ repair
Repair Base64 | Tools | Base64
Unfortunately, you cannot decode your string just by removing invalid characters. I suppose that your string contains some encrypted data and the "invalid characters" (such as $ or :) are used to concatenate various pieces needed for decryption.
๐ŸŒ
CodeSpeedy
codespeedy.com โ€บ home โ€บ what is โ€˜bโ€™ in front of string and how to remove that in python?
What is 'b' in front of string & how to remove that in Python - CodeSpeedy
February 7, 2022 - import codecs string1 = b'CodeSpeedy' print(string1) print(type(string1)) string1_aft_decode = codecs.decode(string1) print(string1_aft_decode) print(type(string1_aft_decode))
Top answer
1 of 11
86

The = is padding. <!------------>

Wikipedia says

An additional pad character is allocated which may be used to force the encoded output into an integer multiple of 4 characters (or equivalently when the unencoded binary text is not a multiple of 3 bytes) ; these padding characters must then be discarded when decoding but still allow the calculation of the effective length of the unencoded text, when its input binary length would not be a multiple of 3 bytes (the last non-pad character is normally encoded so that the last 6-bit block it represents will be zero-padded on its least significant bits, at most two pad characters may occur at the end of the encoded stream).

If you control the other end, you could remove it when in transport, then re-insert it (by checking the string length) before decoding.
Note that the data will not be valid Base64 in transport.

Also, Another user pointed out (relevant to PHP users):

Note that in PHP base64_decode will accept strings without padding, hence if you remove it to process it later in PHP it's not necessary to add it back. โ€“ Mahn Oct 16 '14 at 16:33

So if your destination is PHP, you can safely strip the padding and decode without fancy calculations.

2 of 11
39

In JavaScript you could do something like this:

// if this is your Base64 encoded string
var str = 'VGhpcyBpcyBhbiBhd2Vzb21lIHNjcmlwdA=='; 

// make URL friendly:
str = str.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');

// reverse to original encoding
if (str.length % 4 != 0){
  str += ('===').slice(0, 4 - (str.length % 4));
}
str = str.replace(/-/g, '+').replace(/_/g, '/');

See also this Fiddle: http://jsfiddle.net/7bjaT/66/

Top answer
1 of 3
1

The mutt mail user agent (MUA) can delete messages from a mailbox by MIME type. You can even script this.

A message that has an encoded attachment can be matched in mutt with the search expression ~M application. This matches any message that contains a MIME type containing the string application, usually indicating that an attachment is encoded (probably in base64). You may obviously use the more specific application/x-msdownload if you wish.

If the mailbox is called messages.mbox, you may delete all the messages in it that have any attachment that contains the string application from the command line like this:

mutt -e 'push <delete-pattern>"~M application"<enter><quit>"y"' -f messages.mbox

Note that this does not ask for any confirmation before deleting the messages from the mailbox (the "y" at the end is the reply to the question from mutt whether to delete the messages or not before quitting). You may instead want to move the messages into a separate mailbox:

mutt -e 'push <tag-pattern>"~M application"<enter><tag-prefix><save-message>bad.mbox<enter>"y"<quit>"y"' -f messages.mbox

This tags all messages that match the given search expression, saves them to the mailbox bad.mbox, and quits after deleting them from the original mailbox.

2 of 3
0

Have a look at procmail, formail, and mimencode. You can easily set up complicated automated mailbox processing with those, for example to

find and replace all messages in the mbox file containing "Content-Type: application/x-msdownload".

๐ŸŒ
PerlMonks
perlmonks.org
Remove base64 encoded trailing character
hankcoder has asked for the wisdom of the Perl Monks concerning the following question: ยท Hi, in base64 encoded string, I would like to know if there are any future conflict or any complication if I remove encoded strings that ends with equal characters "="
๐ŸŒ
Base64 Decode and Encode
base64decode.net
Base64 Decode and Encode - Online Tool
Our online Base64 decode tool helps you to convert encoded data that has been encoded using the Base64 encoding scheme into its original form.
๐ŸŒ
Base64.Guru
base64.guru โ€บ converter โ€บ decode
Base64 Decode | Base64 Converter | Base64
Please use the Repair Base64 tool to obtain valid Base64 strings, then use the Base64 to Image tool to display or download your images. ... Just remove this part from your current string,decode it under the forced image type decoder/forced png mime type and it should give you your tiny image ...