Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: a bytes-like object is required, not 'Binary' [closed]

I use xmlrpc.server to build a server and use pickle.dumps() to pickling some data. Then I use xmlrpc.client to build a client and use pickle.loads() to unpickle this data.

## server
server = SimpleXMLRPCServer(('0.0.0.0', 5005), allow_none=True)
# in _dispatch method:
result = perform_stuff()
return pickle.dumps(result)

## client
proxy = ServerProxy(f'http://{host}:{port}', allow_none=True)
result = proxy.make_rpc()
return pickle.loads(result.data)

However, I counter the following problems:

I don't know the difference between the bytes-like object and 'Binary'

I try to use bytes(ret) to solve this problem, but it has another one

like image 736
lxg_april Avatar asked Oct 19 '22 08:10

lxg_april


1 Answers

Given a Binary instance bin, you can get the data as a bytes or bytearray instance by bin.data.

I can only guess from the code snippet you provided, but the following should work:

ret = pickle.loads(ret.data)
like image 162
Manuel Jacob Avatar answered Oct 23 '22 13:10

Manuel Jacob