我今天试着写一个小python脚本,但是失败得很惨。为什么下面的代码在从shell调用后会出现以下错误?在
错误
File "./testmod.py", line 15, in <module>
printdnsfile(sys.argv[1])
File "./testmod.py", line 10, in printdnsfile
print(socket.gethostbyname(str(line)))
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
代码
^{pr2}$我在python控制台中测试了socket模块,它的工作与预期一样。我的代码有错误还是配置有问题?在
谢谢。在
输入文件中可能有一个空行。尝试在获取hostbyname之前检查一下您的线路。在
问题可能是} 来调试程序。在
line
不包含预期值。为了确保您可以在失败的行之前添加print line
语句,或者使用^{相关问题 更多 >
编程相关推荐