1

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?

2

1 Answer 1

2

It turns out that base64, as outlined in my question's code, is correct. There was a misinterpretation of the error logs.

So if anyone reading this has a similar problem, let me assure you: base64 is fine, the problem must be something else.

Sign up to request clarification or add additional context in comments.

1 Comment

In my case, I was trying to encode PDF files to Base64 too. and it worked perfectly. You've saved me a alot of time!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.