In xmlrpclib, Binary data needs to be transmitted. Therefore, Binary Objects is used for packaging and the following two functions are written:
Def encodebindata (data ):
Out = StringIO. StringIO ()
Bin = xmlrpclib. Binary ()
Bin. data = data
Bin. encode (out)
Data2 = out. getvalue ()
Return data2
Def decodebindata (data ):
Bin = xmlrpclib. Binary ()
Data1 = bin. decode (data)
Return bin. data
When the decodebindata function is called for decoding, there are always errors and prompts such as "binascii. Error: incorrect padding. Let's take a look at the Binary class definition in xmlrpclib. py:
Def decode (self, data ):
Self. data = base64.decodestring (data)
Def encode (self, out ):
Out. write ("<value> <base64> n ")
Base64.encode (StringIO. StringIO (self. data), out)
Out. write ("</base64> </value> n ")
Binary encoding and decoding actually uses the decodestring and encode of base64, which does not seem to match very well. In base64, encode should be paired with decode, and decodestring and encodestring should be paired. Therefore, we tried to directly use base64 for packaging without using the Binary Objects of xmlrpclib. The two functions are redefined as follows:
Def encodebindata (data ):
Out = StringIO. StringIO ()
Bin = StringIO. StringIO (data)
Base64.encode (bin, out)
Data2 = out. getvalue ()
Return data2
Def decodebindata (data ):
Out = StringIO. StringIO ()
Bin = StringIO. StringIO (data)
Base64.decode (bin, out)
Data2 = out. getvalue ()
Return data2
After testing, there are no problems
The Binary Objects of xmlrpclib is packaged in xml format and can be directly transmitted. You cannot unpack the package immediately after packaging.
From: http://blog.robotercoding.com /? Cat = 5 & paged = 2