views:

462

answers:

2

Hi Everyone, 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 an Attribute Error that says:

AttributeError: type object '_socketobject' has no attribute 'gethostbyname'

I really do not understand what I need to do to solve this issue. If anyone can please help me, I'll be really grateful. I am running Vista 64bit. Could there be a problem with my OS? I have turned down my firewall and everything. Please help me.

+1  A: 

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!

Alex Martelli
Thank you so much... I did not know that.. thanks so much for reply. Cannot tell you how relieved I am. Thanks again.
Sheela
+2  A: 

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.

Roberto Liffredo
Yayyyy!!!! It Worked!! Thanks so much, I have an assignment to be submitted tomorrow and your answer was of great help. I did not know, such a small mistake could cause such a major problem. Thanks again, I really appreciate ur quick reply.. Thanks.
Sheela