By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,592 Members | 1,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,592 IT Pros & Developers. It's quick & easy.

Socket Error

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
You missed the import socket statement. Also the socket.PF_INET should
be socket.AF_INET

Jul 19 '05 #3

P: n/a
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

P: n/a
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

P: n/a

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.