在python中打印时出现UnicodeDecodeError

时间:2017-05-31 05:38:32

标签: python linux unix telnet mainframe

程序:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = '101.72.14.20'
port = 23
s.connect((host, port))
tm = s.recv(1024)
s.close()
print("The time got from the server is %s" % tm.decode('ascii'))

错误:

$ python cli.py
Traceback (most recent call last):
  File "cli.py", line 20, in <module>
     print("The time got from the server is %s" % tm.decode('ascii'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
$

这是一个简单的客户端程序。我试图从服务器上读取内容。它成功读取。但它在打印时显示错误为&#34; UnicodeDecodeError&#34;。任何人都可以帮我解决这个问题。

注意:

101.72.14.20 is a mainframe server. I expect the data is in the form of EBCDIC

0 个答案:

没有答案