Check if a string is encoded in base64 using Python
问题 Is there a good way to check if a string is encoded in base64 using Python? 回答1: This isn't possible. The best you could do would be to verify that a string might be valid Base 64, although many strings consisting of only ASCII text can be decoded as if they were Base 64. 回答2: import base64 import binascii try: base64.decodestring("foo") except binascii.Error: print "no correct base64" 回答3: I was looking for a solution to the same problem, then a very simple one just struck me in the head.