我试图从MATLAB调用一个Python函数。在这个Python函数中,输入参数的类型是“byte string”。我无法将“byte string”参数传递给Python
我尝试使用ipc创建一个服务器-客户端应用程序,其中server是一个纯Python应用程序,client是一个调用Python函数的MATLAB应用程序。我已经在python3.7环境中安装了Anaconda。
Python服务器代码: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客户端代码(用于测试):
^{pr2}$
在Python中执行时,上面的服务器-客户机对工作正常。
现在在命令行中尝试与上述Python客户机代码等效的MATLAB:>> 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
我知道我在上面传递了一个正常的字符串,这就是出错的原因。我要求将上述参数“secret password”作为“字节字符串”发送。怎么能做到呢?