[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

AttributeError: module 'socket' has no attribute 'timeout'



Hello,  I’m using python3.5, python3.7 on Debian 9 stretch
This is my code:

———————-
import socket

host =  'google.com
port = 80

try:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(0.1)
    result = sock.connect_ex((host, port))
    if result == 0:
        print('Port is UP')
    else:
        print('Port is DOWN')
except socket.timeout as e:
    print(e)
——————————


When I execute my code I receive this error

***************
Traceback (most recent call last):
  File "/root/python/projects/test/socket.py", line 7, in <module>
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
AttributeError: module 'socket' has no attribute 'AF_INET'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "socket.py", line 1, in <module>
    import socket
  File "/root/python/projects/test/socket.py", line 14, in <module>
    except socket.timeout as e:
AttributeError: module 'socket' has no attribute 'timeout'
******************
recently everything worked fine, but some time ago this error appeared.  And on other OS (Ubuntu, FreeBSD), the code works without errors. Please help:) sorry for my English 

--
С уважением,
Артём

Reply to: