I'm new to Python and I do have an issue that is bothering me.
I use the following code to get a base64 string representation of my zip file.
with open( "C:\\Users\\Mario\\Downloads\\exportTest1.zip",'rb' ) as file:
zipContents = file.read()
encodedZip = base64.encodestring(zipContents)
$fileName = "C:\Users\Mario\Downloads\exportTest1.zip"
$fileContentBytes = [System.IO.File]::ReadAllBytes($fileName)
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
From the base64 package doc:
"Encode the bytes-like object s, which can contain arbitrary binary data, and return
bytes containing the base64-encoded data, with newlines (
b"\n") inserted after every 76 bytes of output, and ensuring that there is a trailing newline, as per RFC 2045 (MIME)."
You want to use
"Encode the bytes-like object s using Base64 and return the encoded
import base64 with open("test.zip", "rb") as f: encodedZip = base64.b64encode(f.read()) print(encodedZip.decode())
decode() will convert the binary string to text.