I'm writing a Python program to build s an XML file that will be processed by Biztalk to import data into another system.
One of the fields allows me to include a file in a base64binary
field.
I'm doing so using base64.b64encode(data)
:
import base64
data = open('Test.pdf', 'rb').read()
print base64.b64encode(data)
However the expected data must begin with a 0x
.
Looking into a sample XML file I find that the example encoded data looks like hexadecimal (no symbols and no letters above F
) so I also tried that with no luck:
import binascii
print '0x' + binascii.hexlify(data)
How can you use Python to properly encode a file to insert it into a base64binary
XML field?