필터 지우기
필터 지우기

How could a 'byte string' input argument be passed to a python function called from MATLAB ?

조회 수: 2 (최근 30일)
I am trying to create a server-client application using ipc, where server is a pure Python application and client is a MATLAB application which calls python functions. I have Anaconda installed with Python 3.7 environment.
Python Server code :
from multiprocessing.connection import Listener
address = ('localhost', 6000) # family is deduced to be 'AF_INET'
listener = Listener(address, authkey=b'secret password')
conn = listener.accept()
print('connection accepted from', listener.last_accepted)
while True:
msg = conn.recv()
print(msg)
if msg == 'close':
conn.close()
break
listener.close()
Python client code :
from multiprocessing.connection import Client
address = ('localhost', 6000)
conn = Client(address, authkey=b'secret password')
conn.send('close')
# can also send arbitrary objects:
# conn.send(['a', 2.5, None, int, sum])
conn.close()
When executed in Python, the above pair is working fine.
Now trying MATLAB equivalent of above Python client code in command line :
>> mp_pyModule = py.importlib.import_module('multiprocessing.connection');
>> client_fn = mp_pyModule.Client;
>> address = py.tuple({'localhost',int16(6000)});
>> conn = client_fn(address,pyargs('authkey','secret password'));
Error using connection>Client (line 495)
Python Error: TypeError: authkey should be a byte string
I require the above argument 'secret password' to be sent as a 'byte string'. Is there any method ?
Unsupported types to Python does not mention anything about this. Is there any other limitation ?
  댓글 수: 4

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by