I have some data in a database that is base64 encoded
I am decoding it easily enough with
b64 = base64.b64decode(row[2])
however I now need to search the decoded data for various text strings and get the offsets of said strings. The decoded data is binary i.e. it contains lots of non-printables, NULLs etc.
I have tried
ofs = b64.find('content')
but get an error TypeError: Type str doesn't support the buffer API
which shows I am clearly barking up the wrong tree
I am new to Python but for various reasons want to try and get a solution using it - any ideas please?
Search for a bytes object instead of a str
ofs = b64.find(b'content')
or a little less hard-coded way
search = 'content'
ofs = b64.find(bytes(search))
As ofs in encoded as bytes, you should look for a corresponding object inside it ;).
From the Docs, bytes when used as function returns a new bytes object:
bytes([source[, encoding[, errors]]])
Return a new “bytes” object, which is an immutable sequence of integers in the range 0 <= x < 256. bytes is an immutable version of bytearray – it has the same non-mutating methods and the same indexing and slicing behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With