views:

63

answers:

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,...]?

A: 

Try a bytearray.

katrielalex
A: 

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

Raz