Skip to content Skip to sidebar Skip to footer

Traceback (most Recent Call Last): File "", Line 1, In Attributeerror: Module 'socket' Has No Attribute 'close'

I need to write a program that retrieves the IP addresses of a list of domain names. The simple example can be shown here: >>> import socket >>> socket.gethostbyn

Solution 1:

The socket in your code refers to the socket module, which has no close function. A new module level close function has been added in Python 3.7, but it requires a socket descriptor as an argument. If I get it right, you want to call the close method of socket object, not the module. In your case you don't need to close any connection.

Solution 2:

You don't create a socket here neither you bind it to any port. What socket.gethostbyname('google.com') does is translate a host name to IPv4 address format. The method .close() has effect in open connections.

Post a Comment for "Traceback (most Recent Call Last): File "", Line 1, In Attributeerror: Module 'socket' Has No Attribute 'close'"