Gerson Souto
Gerson Souto

Reputation: 1

How can I register a function returning a base64Binary element?

I need to return a base64Binary to the client application, and I could only return "str" and "int" in "returns" parameter of "register_function" function.

I tried:

from SimpleXMLRPCServer import SimpleXMLRPCServer

dispatcher = .....

base64Binary = base64.b64encode
dispatcher.register_function('fala', speech, args={'frase': str}, returns={'mp3': base64Binary})

and I get:

TypeError: unknonw type <function b64encode at 0x7f15a93c4dc0> for marshalling

I need produce the xsd:base64Binary type in the resulting xml.

Upvotes: 0

Views: 51

Answers (1)

pippo1980
pippo1980

Reputation: 3096

import base64
 
byt = b'poppppo'
 
base64Binary = base64.b64encode(byt).decode("utf-8")

print(base64Binary, type(base64Binary))

out :

cG9wcHBwbw== <class 'str'>

and :

from io import StringIO
import base64

bas = StringIO('cG9wb3BvcG9wb3BvcG9wb3BvcG9wb2xvbG9sb2xv')

print(bas , type(bas))

print(bas.read() , type(bas.read()))



base64Binary = base64.b64decode('cG9wb3BvcG9wb3BvcG9wb3BvcG9wb2xvbG9sb2xv').decode('utf-8)')

print(base64Binary, type(base64Binary))

bas.seek(0)

base64Binary = base64.b64decode(bas.read()).decode('utf-8')

print(base64Binary, type(base64Binary))

out :

<_io.StringIO object at 0x7a07b3d61090> <class '_io.StringIO'>
cG9wb3BvcG9wb3BvcG9wb3BvcG9wb2xvbG9sb2xv <class 'str'>
popopopopopopopopopopololololo <class 'str'>
popopopopopopopopopopololololo <class 'str'>
> 

Upvotes: 0

Related Questions