473,382 Members | 1,750 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,382 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 9147
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.