Sandhya Jha
Sandhya Jha

Reputation: 386

Convert file stream to base64 python

I have read the file stream of a zip file by the following code:

file = open(source_url, "rb")  
data = file.read()  
file.close()  
byte_arr = base64.b64encode(data)

Now I am trying to call a webservice which accepts base64Binary format of data (byte array written in java). If I send byte_arr to the web-service I get client error:
Fault env:Client: Caught exception while handling request: unexpected element type: expected={http://www.w3.org/2001/XMLSchema}base64Binary, actual={http://www.w3.org/2001/XMLSchema}string

Please suggest why is base64 module not working for me.
type(byte_arr) is still string.
With thanks,
Sandhya

Upvotes: 4

Views: 6265

Answers (1)

Constantinius
Constantinius

Reputation: 35089

I guess there's nothing wrong with your base64 encoding. It seems like it is not embedded in a correct XML document. Probably the error is when you send your data, maybe you should check that piece of code.

Upvotes: 2

Related Questions