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.
decode the bytes to produce a str:
b = b'1234'
print(b.decode('utf-8')) # '1234'
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>
Remove 'b' character do in front of a string literal in Python 3 - Stack Overflow
Remove trailing "=" when base64 encoding - Stack Overflow
sed - Remove all base64 blocks from a file - Unix & Linux Stack Exchange
How to Decode base64 string value using uipath?
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.
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.
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/
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.
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".
input:
s = 'เจ '
a = s.encode('ascii', 'backslashreplace')
print(a)
output:
b'\\u0a05'
how do I get rid of the b'\ ? i just want it to say \u0a05