简体   繁体   English

Python属性错误:类型对象'_socketobject'没有属性'gethostbyname'

[英]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.

相关问题 Python Web套接字AttributeError:类型对象'_socketobject'没有属性'gethostbyname' - Python Web Socket AttributeError: type object '_socketobject' has no attribute 'gethostbyname' AttributeError:类型对象“ _socketobject”没有属性“ error” - AttributeError: type object '_socketobject' has no attribute 'error' AttributeError: '_socketobject' 对象没有属性 'error' - AttributeError: '_socketobject' object has no attribute 'error' _socketobject'对象没有属性'bing' - _socketobject' object has no attribute 'bing' AttributeError:'_socketobject'对象没有属性'bind' - AttributeError: '_socketobject' object has no attribute 'bind' Python 属性错误:类型对象没有属性 - Python Attribute Error: type object has no attribute Python属性错误-类型对象没有属性 - Python Attribute Error - Type Object has no Attribute 'module'对象没有属性'gethostbyname'错误谷歌应用引擎 - 'module' object has no attribute 'gethostbyname' error google app engine AttributeError:'_socketobject'对象没有属性'set_tlsext_host_name' - AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name' 类型对象没有属性Python - Type Object has no attribute Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM