469,579 Members | 1,112 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Socket Error

When I try to open a socket with python i get the following error:

Traceback (most recent call last):
File "./mailer", line 3, in ?
sock = socket.socket(socket.PF_INET, socket.SOCK_STREAM)
NameError: name 'socket' is not defined

the code is:

#!/usr/bin/python

sock = socket.socket(socket.PF_INET, socket.SOCK_STREAM)
sock.connect(("mail.oasd.k12.wi.us", 25))
sock.send("HELO")
print sock.recv(8192)
sock.close()

Jul 19 '05 #1
5 7511
ki*************@gmail.com wrote:
When I try to open a socket with python i get the following error:

Traceback (most recent call last):
File "./mailer", line 3, in ?
sock = socket.socket(socket.PF_INET, socket.SOCK_STREAM)
NameError: name 'socket' is not defined

the code is:

#!/usr/bin/python

sock = socket.socket(socket.PF_INET, socket.SOCK_STREAM)
sock.connect(("mail.oasd.k12.wi.us", 25))
sock.send("HELO")
print sock.recv(8192)
sock.close()

tried:
import socket
???
Jul 19 '05 #2
You missed the import socket statement. Also the socket.PF_INET should
be socket.AF_INET

Jul 19 '05 #3
ki*************@gmail.com wrote:
NameError: name 'socket' is not defined


You forgot to import the socket module:

import socket

regards,
Achim
Jul 19 '05 #4
Thanks everybody, it works now. I thought I needed to do something like
that but it didn't show it in the tutorial so I decided to ask here.

Jul 19 '05 #5

kingofearth....@gmail.com wrote:
Thanks everybody, it works now. I thought I needed to do something like that but it didn't show it in the tutorial so I decided to ask here.


Where was the tutorial? If it's in the Python docs, perhaps you could
submit a patch to fix it ... ;-)

M@

Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robert A. van Ginkel | last post: by
2 posts views Thread by Droopy | last post: by
2 posts views Thread by Rene Sørensen | last post: by
7 posts views Thread by | last post: by
10 posts views Thread by Hendrik van Rooyen | last post: by
2 posts views Thread by manasap | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.