2

I'm using a SOAP based web service that expects an image element in the form of a 'ByteArray' described in their docs as being of type 'byte[]' - the client I am using is the Python based suds library.

Problem is that I am not exactly sure how to represent the ByteArray in for this service - I presume that it should look something like the following list:

[71,73,70,56,57,97,1,0,1,0,128,0,0,255,255,255,0,0,0,33,249,4,0,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59]

Now when I send this as part of the request, the service complains with the message: Base64 sequence length (105) not valid. Must be a multiple of 4. Does this mean that I would have to pad each member with zeroes to make them 4 long, i.e. [0071,0073,0070,...]?

2 Answers 2

2

I got it figured in the end - what the web service meant by a ByteArray (byte[]) looked something like:

/9j/4AAQSkZJRgABAgEAYABgAAD/7gAOQWRvYmUAZAAAAAAB...

... aha, base 64 (not anywhere in their docs, I hasten to add)...

so I managed to get it working by using this:

encoded_data = base64.b64encode(open(file_name, 'rb').read())
strg = ''
for i in xrange((len(encoded_data)/40)+1):
    strg += encoded_data[i*40:(i+1)*40]
# strg then contains data required

I found the inspiration right here - thanks to Doug Hellman

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

1 Comment

Thank you for posting your solution, this is exactly what I was looking for
0

Try a bytearray.

Comments

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.