开发者

Python attribute error: type object '_socketobject' has no attribute 'gethostbyname'

开发者 https://www.devze.com 2022-12-13 05:03 出处:网络
I am trying to do this in my program: dest = socket.gethostbyname(host) I have included the line: from socket import *

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'

I am running 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. That import * is horrible practice, by the way: do, instead, import socket, and then socket.gethostbyname will work just fine!

0

精彩评论

暂无评论...
验证码 换一张
取 消