473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 9128
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
2
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job...
7
by: | last post by:
Hi all, I have a simple .aspx page running on net 2.0 that is trying to do a http post to a remote server. Here is the code Private Function ProcessRequests(ByVal strbody As String) As String...
1
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
2
by: John Nagle | last post by:
Here's a strange little bug. "socket.getaddrinfo" blows up if given a bad domain name containing ".." in Unicode. The same string in ASCII produces the correct "gaierror" exception. Actually,...
10
by: John Nagle | last post by:
Here are three network-related exceptions. These were caught by "except" with no exception type, because none of the more specific exceptions matched. This is what a traceback produced: 1....
14
by: ahlongxp | last post by:
Hi, everyone, I'm implementing a simple client/server protocol. Now I've got a situation: client will send server command,header paires and optionally body. server checks headers and decides...
10
by: Hendrik van Rooyen | last post by:
While doing a netstring implementation I noticed that if you build a record up using socket's recv(1), then when you close the remote end down, the recv(1) hangs, despite having a short time out...
2
by: manasap | last post by:
Hi all! I've written a server and a client application using asynchronous sockets.The client sends data packets for every 7 seconds.The server receives the packets. This process proceeds...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.