Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'exception': 0.03; 'syntax': 0.03; 'elif': 0.04; 'debug': 0.05; 'socket': 0.05; 'sys': 0.05; 'except:': 0.07; 'try:': 0.07; 'python': 0.09; '0.1': 0.09; 'hostname': 0.09; 'port))': 0.09; 'sys.argv[0]': 0.09; 'sys.exit(2)': 0.09; 'subject:error': 0.11; '>>': 0.16; '1):': 0.16; '2.0:': 0.16; 'delay,': 0.16; 'pdb': 0.16; 'syntaxerror:': 0.16; 'true:': 0.16; 'to:name:python- list@python.org': 0.20; 'import': 0.21; '>': 0.23; 'raise': 0.24; 'skip:[ 10': 0.26; 'skip:# 10': 0.27; 'message- id:@mail.gmail.com': 0.27; 'interface': 0.27; 'this?': 0.28; 'address)': 0.29; 'socket,': 0.29; '8bit%:5': 0.29; 'skip:& 10': 0.29; 'figure': 0.30; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'server': 0.35; 'data,': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'client': 0.36; 'being': 0.37; 'why': 0.37; 'drop': 0.37; 'received:209': 0.37; 'data': 0.37; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'think': 0.40; 'address': 0.60; 'skip:u 10': 0.60; 'life': 0.66; 'address,': 0.79; '1060': 0.84; 'random,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=HEtcQ0Hu6XndsfvHE8YtIWk5kW6HJ9GGHKa8MK7cQDc=; b=tUQMrRs8Aj7Odv3pTETKyjLRiuqDhoJ5K9BrqGfsXiB9UylCmB2/Rd/zrY7sJHjAqZ x8UgT9EESPJ/Lnw3AqAMGILkuf9ACNg7J+pZelGsT++kD7IYoXDFCLoB87fgWnZSB7oR VSL4Ik6edydaxhd/HwNP2FMqpVi3NsCM/UqweR5q1KhCtwoZZnlUMRXTL4SroLZFJCxB sXWASGXjq2nW6RJSZrPQURFtoRuzl4JbB95p8AlR7mNjNEXOT1WuV82XT1d2lkOP2Erc 3cwX1v0LOn+tvQ18IaUYxi4IMUXWHgqq9EZi6uNpcF/kKgeZVxlD+Ga3A39gr4Gjy1NA +ArQ== X-Received: by 10.60.8.40 with SMTP id o8mr16386947oea.112.1360014607063; Mon, 04 Feb 2013 13:50:07 -0800 (PST) MIME-Version: 1.0 From: Rodrick Brown Date: Mon, 4 Feb 2013 16:49:37 -0500 Subject: error in except To: "python-list@python.org" Content-Type: multipart/alternative; boundary=e89a8ff1c7ea8b19b604d4ed1326 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 117 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360014616 news.xs4all.nl 6860 [2001:888:2000:d::a6]:55882 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38142 --e89a8ff1c7ea8b19b604d4ed1326 Content-Type: text/plain; charset=ISO-8859-1 For the life of me I cant figure out why this exception is being thrown. How could I use pdb to debug this? $ python udp_local2.py server File "udp_local2.py", line 36 except: ^ SyntaxError: invalid syntax #!/usr/bin/env python import random, socket, sys s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) MAX = 65535 PORT = 1060 if 2 <= len(sys.argv) <= 3 and sys.argv[1] == 'server': interface = sys.argv[2] if len(sys.argv) > 2 else '' s.bind((interface, PORT)) print 'Listening at', s.getsockname() while True: data, address = s.recvfrom(MAX) if random.randint(0, 1): print 'The client at', address, 'says:', repr(data) s.sendto('Your data was %d bytes' % len(data), address) else: print 'Pretending to drop packet from', address elif len(sys.argv) == 3 and sys.argv[1] == 'client': hostname = sys.argv[2] s.connect((hostname, PORT)) print 'Client socket name is', s.getsockname() delay = 0.1 while True: s.send('This is another message') print 'Waiting up to', delay, 'seconds for a reply' s.settimeout(delay) try: data = s.recv(MAX) except socket.timeout: delay *= 2 if delay > 2.0: raise RuntimeError('I think the server is down') except: raise else: break print 'The server says', repr(data) else: print >> sys.stderr, 'usage: %d server []' % sys.argv[0] print >> sys.stderr, ' or: %d client ' % sys.argv[0] sys.exit(2) --e89a8ff1c7ea8b19b604d4ed1326 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
For the life of me I cant figure out why t= his exception is being thrown.=A0
How could I use pdb to de= bug this?=A0

$ python udp_local2.py server
=A0 File "udp_local2.py", line 36
=A0 =A0 except:
=
=A0 =A0 =A0 =A0 =A0^
SyntaxError: invalid syntax
=


#!/usr/bin/env python

import random, socket, sys
s =3D socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

<= /div>
MAX =3D 65535
PORT =3D 1060

if= 2 <=3D len(sys.argv) <=3D 3 and sys.argv[1] =3D=3D 'server':=
=A0 =A0 interface =3D sys.argv[2] if len(sys.argv) > 2 else ''
=A0 =A0 s.bind((interface, PORT))
=A0 =A0 print 'Lis= tening at', s.getsockname()
=A0 =A0 while True:
=A0= =A0 =A0 =A0 data, address =3D s.recvfrom(MAX)
=A0 =A0 =A0 =A0 if random.randint(0, 1):
=A0 =A0 =A0 =A0 =A0= =A0 print 'The client at', address, 'says:', repr(data)
=A0 =A0 =A0 =A0 =A0 =A0 s.sendto('Your data was %d bytes' %= len(data), address)
=A0 =A0 =A0 =A0 else:
=A0 =A0 =A0 =A0 =A0 =A0 print 'Pretendi= ng to drop packet from', address

elif len(sys.= argv) =3D=3D 3 and sys.argv[1] =3D=3D 'client':
=A0 =A0 h= ostname =3D sys.argv[2]
=A0 =A0 s.connect((hostname, PORT))
=A0 =A0 print 'Client soc= ket name is', s.getsockname()
=A0 =A0 delay =3D 0.1
=A0 =A0 while True:
=A0 =A0 =A0 =A0 s.send('This is another = message')
=A0 =A0 =A0 =A0 print 'Waiting up to', delay, 'seconds for a re= ply'
=A0 =A0 =A0 =A0 s.settimeout(delay)
=A0 =A0 = =A0 =A0 try:
=A0 =A0 =A0 =A0 =A0 =A0 data =3D s.recv(MAX)
=A0 =A0 =A0 =A0 except socket.timeout:
=A0 =A0 =A0 =A0 =A0 =A0 delay *=3D 2
=A0 =A0 =A0 =A0 =A0 =A0= if delay > 2.0:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 raise Runtime= Error('I think the server is down')
=A0 =A0 =A0 =A0 =A0 = =A0 except:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 raise
=A0 =A0 =A0 =A0 =A0 =A0 else:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bre= ak
=A0 =A0 =A0 =A0 print 'The server says', repr(data)
=A0 =A0 else:
=A0 =A0 =A0 =A0 print >> sys.stderr, = 'usage: %d server [<interfae>]' % sys.argv[0]
=A0 =A0 =A0 =A0 print >> sys.stderr, ' =A0 or: %d client <= ;host>' % sys.argv[0]
=A0 =A0 =A0 =A0 sys.exit(2)


--e89a8ff1c7ea8b19b604d4ed1326--