Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.maint.python > #11418 > unrolled thread

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

Started byArtem Golubev <agolubev.n@gmail.com>
First post2019-04-25 09:30 +0200
Last post2019-04-25 10:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.debian.maint.python


Contents

  AttributeError: module 'socket' has no attribute 'timeout' Artem Golubev <agolubev.n@gmail.com> - 2019-04-25 09:30 +0200
    Re: AttributeError: module 'socket' has no attribute 'timeout' Alexandros Afentoulis <alexaf@bloom.re> - 2019-04-25 10:20 +0200
    Re: AttributeError: module 'socket' has no attribute 'timeout' Neil Williams <codehelp@debian.org> - 2019-04-25 10:20 +0200

#11418 — AttributeError: module 'socket' has no attribute 'timeout'

FromArtem Golubev <agolubev.n@gmail.com>
Date2019-04-25 09:30 +0200
SubjectAttributeError: module 'socket' has no attribute 'timeout'
Message-ID<xQGZr-3fY-3@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

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

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

[toc] | [next] | [standalone]


#11419

FromAlexandros Afentoulis <alexaf@bloom.re>
Date2019-04-25 10:20 +0200
Message-ID<xQHLP-3OM-1@gated-at.bofh.it>
In reply to#11418
On 4/25/19 10:04 AM, Artem Golubev wrote:
> Hello,  I’m using python3.5, python3.7 on Debian 9 stretch
> This is my code:

[snip]

> 
> 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'
> 

Hi,

the problem is you've named your file 'socket', and that precedes the 
python module 'socket' when importing. Try renaming it.

Since your question is not specific to debian python packaging though, 
it would be probably better to ask elsewhere, e.g. 
https://stackoverflow.com/

Cheers

[toc] | [prev] | [next] | [standalone]


#11420

FromNeil Williams <codehelp@debian.org>
Date2019-04-25 10:20 +0200
Message-ID<xQHLQ-3OM-7@gated-at.bofh.it>
In reply to#11418

[Multipart message — attachments visible in raw view] — view raw

On Thu, 25 Apr 2019 10:04:46 +0300
Artem Golubev <agolubev.n@gmail.com> wrote:

> Hello,  I’m using python3.5, python3.7 on Debian 9 stretch

Simply rename the script and delete any socket.pyc file in the same
directory.

* Do not name your script using the name of a module that you will be
  importing:

>   File "/root/python/projects/test/socket.py", line 7, in <module>

That should be .../test/socket-test.py or socket-script.py
anything except the name of the module you will be importing from
elsewhere.

> This is my code:

The code itself is fine.

> 
> ———————-
> import socket
> 
> host =  'google.com’

The quotation marks here were mangled by your email client but once
that is fixed, the code works fine.

> 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
> 
> -- 
> С уважением,
> Артём


-- 


Neil Williams
=============
http://www.linux.codehelp.co.uk/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.maint.python


csiph-web