[英]Python attribute error: type object '_socketobject' has no attribute 'gethostbyname'
I am trying to do this in my program: 我想在我的程序中这样做:
dest = socket.gethostbyname(host)
I have included the line: 我已经包括这条线:
from socket import *
in the beginning of the file. 在文件的开头。
I am getting this error: 我收到此错误:
AttributeError: type object '_socketobject' has no attribute 'gethostbyname' AttributeError:类型对象'_socketobject'没有属性'gethostbyname'
I am running Vista 64bit. 我正在运行Vista 64bit。 Could there be a problem with my OS? 我的操作系统有问题吗? I have turned down my firewall and everything. 我拒绝了我的防火墙和一切。
You shoulod either use 你要么使用
import socket
dest = socket.gethostbyname(host)
or use 或使用
from socket import *
dest = gethostbyname(host)
Note: the first option is by far the recommended one. 注意:第一个选项是推荐的选项。
After from socket import *
, you'd need to call just the barename gethostbyname
-- the barename socket
now refers to a type, not to the module. from socket import *
,你只需要调用barename gethostbyname
- barename socket
现在引用一个类型,而不是模块。 That import *
is horrible practice, by the way: do, instead, import socket
, and then socket.gethostbyname
will work just fine! 那个import *
是一种可怕的做法,顺便说一句:相反, import socket
, 然后 socket.gethostbyname
将正常工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.