简体   繁体   English

将文件流转换为base64 python

[英]Convert file stream to base64 python

I have read the file stream of a zip file by the following code: 我已通过以下代码读取了zip文件的文件流:

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). 现在我试图调用一个接受base64Binary数据格式的web服务(用java编写的字节数组)。 If I send byte_arr to the web-service I get client error: 如果我将byte_arr发送到Web服务,我会收到客户端错误:
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 故障环境:客户端:处理请求时发生异常:意外元素类型:expected = {http://www.w3.org/2001/XMLSchema} base64Binary,actual = {http://www.w3.org/2001/XMLSchema }串

Please suggest why is base64 module not working for me. 请说明为什么base64模块对我不起作用。
type(byte_arr) is still string. type(byte_arr)仍然是字符串。
With thanks, 谢谢,
Sandhya 桑德亚

I guess there's nothing wrong with your base64 encoding. 我猜你的base64编码没什么问题。 It seems like it is not embedded in a correct XML document. 它似乎没有嵌入到正确的XML文档中。 Probably the error is when you send your data, maybe you should check that piece of code. 可能错误是您发送数据时,也许您应该检查那段代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM