We can use different keywords to implement the string encoding from base64 module.
Start by importing the module like so:
import base64
# then, either:
"the string to be converted".encode("base64")
or add the "strict" option
"the string to be converted".encode("base64", "strict")
orbase64.encode("the string to be converted")
base64.encodestring("the string to be converted")
base64.b64encode("the string to be converted")
base64.standard_b64encode("the string to be converted")
base64.urlsafe_b64encode("the url string to be converted")
The first two methods will yield \n
as the tail of the output.
Those could be "dangerous" for authentication. Because if we forgot to include the front-end converter (such as in JavaScript
, like adding replace
or other), or other string filter(s) within the Python itself, the stuff would fail.
And if the certain API we're experimenting with is implementing usage filters (which is for certain), we could be blacklisted, because of the constant failures. And then, with many lucks, our connection/machine might be detected as a legit spammer. YAY!
Well, that would rarely happen.
In Conclusion
It's recommended to use the others besides the first two. The:
base64.b64encode("the string to be converted")
base64.standard_b64encode("the string to be converted")
base64.urlsafe_b64encode("the url string to be converted")
Official documentation
base64
library documentation
No comments:
Post a Comment
Tell me what you think...