import subprocess
print('$ nslookup') p = subprocess.Popen(['nslookup'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, err = p.communicate(b'set q=mx\npython.org\nexit\n') print(output.decode('utf-8')) print('Exit code:', p.returncode)
运行后出现 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 2: invalid continuation byte
改为gbk后可行,运行结果如下 $ nslookup 默认服务器: 69.226.101.202.other.jj.jx.dynamic.163data.com.cn Address: 202.101.226.69
服务器: 69.226.101.202.other.jj.jx.dynamic.163data.com.cn Address: 202.101.226.69
python.org MX preference = 50, mail exchanger = mail.python.org > Exit code: 0
我也碰到了同样的问题,不知是否和操作系统有关,用的win7 32bit
我也是啊,我用的是Windows7的,64位的
应该是进行请求的返回字端中有中文,我的也出现这种情况了
谢谢。
这个太赞了,想了一会才想通
Sign in to make a reply
G-Master-G
import subprocess
print('$ nslookup') p = subprocess.Popen(['nslookup'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, err = p.communicate(b'set q=mx\npython.org\nexit\n') print(output.decode('utf-8')) print('Exit code:', p.returncode)
运行后出现 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 2: invalid continuation byte
改为gbk后可行,运行结果如下 $ nslookup 默认服务器: 69.226.101.202.other.jj.jx.dynamic.163data.com.cn Address: 202.101.226.69
python.org MX preference = 50, mail exchanger = mail.python.org > Exit code: 0