[Tutor] exception problems in socket programming

Chris Hengge pyro9219 at gmail.com
Thu Nov 16 06:49:45 CET 2006


I ran this code based on yours:

import socket, sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    s.connect(('something.com', 5000))
except socket.error, (value, message):
    if s:
        s.close()
    print "Could not open socket: " + message
raw_input("\nPress any key")

And I got this result:
Could not open socket: getaddrinfo failed

Press any key

Do you need to put quotes around something.com like I did?

On 11/15/06, Vinay Reddy <vinayvinay at gmail.com> wrote:
>
> Hi,
> I'm trying to do some simple network programming in Python, but am
> stuck with exception problems. Here's the relevant code snippet:
>
> self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>       try:
>          self.s.connect((something.com, 5000))
>       except socket.error, (value, message):
>          if self.s:
>             self.s.close()
>          print "Could not open socket: " + message
>          sys.exit(1)
>
> I was testing for a timeout exception (which is 60 seconds by
> default), but after the timeout I get the following error:
>   File "./client.py", line 54, in connect
>     except socket.error, (value, message):
> ValueError: need more than 1 value to unpack
>
> I googled and found something on ValueError, but I couldn't see how it
> applied here.
>
> I'd appreciate any help.
>
> Thanks,
> Vinay
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061115/82717893/attachment.htm 


More information about the Tutor mailing list