-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"UnicodeDecodeError: 'utf8' codec can't decode error when calling matlab #227
Comments
PS: my environment is python2.7+matlab2013b |
Hei, do you address this problem. Recently I also have encountered the same problem but do not know why |
I meet the problem too. I find the error happened when matlab function return a Chinese error information. So I change the language of system from Chinese to English. |
I solve the problem by setting the language of matlab into English. I think the problem only happens when it return the result from matlab to python, and somehow the result contains some special letters/characters from other languages which causes the error mentioned above. |
1、【matlabCode】
function ret=testFun
a=20;
b=10;
ret=a+b;
2、【Python Code】
matlab=pymat.Matlab()
matlab.start()
func_file=u"G:/Matlab/MyMatlab/testFun.m".decode("utf-8")
res2=matlab.run_func(func_file)
3、【The errors】
Starting MATLAB on ZMQ socket tcp://127.0.0.1:53224
Send 'exit' command to kill the server
.....MATLAB started and connected!
Traceback (most recent call last):
File "G:/Python/quanGeek/model/test.py", line 88, in
res2=matlab.run_func(func_file)
File "D:\Anaconda\lib\site-packages\pymatbridge-0.6.dev0-py2.7.egg\pymatbridge\pymatbridge.py", line 311, in run_func
nargout=nargout)
File "D:\Anaconda\lib\site-packages\pymatbridge-0.6.dev0-py2.7.egg\pymatbridge\pymatbridge.py", line 274, in _json_response
return json.loads(self._response(**kwargs), object_hook=decode_pymat)
File "D:\Anaconda\lib\site-packages\pymatbridge-0.6.dev0-py2.7.egg\pymatbridge\pymatbridge.py", line 232, in _response
resp = self.socket.recv_string()
File "D:\Anaconda\lib\site-packages\zmq\sugar\socket.py", line 403, in recv_string
return b.decode(encoding)
File "D:\Anaconda\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xca in position 22: invalid continuation byte
MATLAB closed
4、Then I debuge the errors , I found the error is caused by
the codeing:
def decode(input, errors='strict'):
return codecs.utf_8_decode(input, errors, True) in "D:\Anaconda\Lib\encodings\utf_8.py" file
5、the reason is the input parameter of 'input' is
'{"content":{"stdout":"�������̫�ࡣ"},"result":"","stack":[],"success"'
it look like that 'stdout' paramter has error code , but how could I resolve it ? the problem has block me for almost 2 weeks, would you help me ?
PS: [the error snapshot ]
The text was updated successfully, but these errors were encountered: