im7
im7

Reputation: 673

Can not open a socket with Python

I am taking a class in Coursera with Michigan University on Python and the professor showed three lines of code that establish a connection. The first imports the library, the second opens a socket and the third establishes a connection. However, I got an error message after the second line:

        import socket

        mysock = socket.socket(socket.AF_INET, socket.sock_STREAM)

        mysock.connect(( 'www.py4inf.com', 80))

Error message:

        Traceback (most recent call last):

        File "<ipython-input-12-2ff379ebad44>", line 1, in <module>
        mysock = socket.socket(socket.AF_INET, socket.sock_STREAM)

        AttributeError: 'module' object has no attribute 'sock_STREAM'

I researched the web on that error and the advice that is give is to remove from working directory file named socket.py. However, in my case the working directory is empty. Thank you for your comments.

Upvotes: 0

Views: 936

Answers (1)

negacao
negacao

Reputation: 1274

Give socket.SOCK_STREAM a try (note the case change).

Upvotes: 3

Related Questions