Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert file stream to base64 python

Tags:

python

base64

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

like image 700
Sandhya Jha Avatar asked Nov 21 '25 07:11

Sandhya Jha


1 Answers

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.

like image 87
Constantinius Avatar answered Nov 22 '25 20:11

Constantinius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!