[Tutor] parsing errors for try/except handling

Brett Kelly bkelly@sourcereview.net
Fri May 9 03:19:02 2003


--uZ3hkaAS1mZxFaxD
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable


instead of:

except error:
    response=3D

maybe try:

except Exception, e:
    response =3D e

just a thought, hth

brett

Sometime around Fri, May 09, 2003 at 01:49:01AM -0400, noc waltzed in like =
he freakin' owned the joint and start spouting off about:
> I'm working on a new script.
>=20
> I'm reading a file that contains a list of hosts, user ids, and passwords.
> It's getting parsed into a list of lists like so:
> [[host, userid, password],[host, userid, password],...]
>=20
> Now I'm telnetting to each host, and issuing some commands, and returning
> the data:
>=20
> def nfscheck(entry):
>     try:
>         tn=3Dtelnetlib.Telnet(entry[0])
>     except error:
>         response=3D
>     else:
>         tn.read_until('login: ','15')
>         tn.write(entry[1]+'\n')
>         tn.read_until('Password: ','15')
>         tn.write(entry[2]+'\n')
>         tn.read_until('$','15')
>         tn.write('ls\n')
>         response=3Dtn.read_until('$','15')
>         tn.write('exit\n')
>     finally:
>         return response
>=20
> Now, sometimes these hosts are down for whatever reason, or maybe the list
> isn't up to date, so I get:
>=20
>   File "C:\Python22\lib\telnetlib.py", line 190, in __init__
>     self.open(host, port)
>   File "C:\Python22\lib\telnetlib.py", line 219, in open
>     raise socket.error, msg
> error: (10060, 'Operation timed out')
>=20
> I realize that in the last line, I have to use 'error' as the name for the
> except statement, but how do assign  'Operation timed out' to my response
> variable?
>=20
> thanks in advance
> bkd
>=20
>=20
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--=20
Brett Kelly
bkelly@sourcereview.net

Want to fall in love with programming all over again? use Python!
http://www.python.org

--uZ3hkaAS1mZxFaxD
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+u1ZVa7gYa9SI8SoRAhlBAJ43/bAJ2DaxRP0VydhqWOoB98AbtACgjf1h
XcJrEAdyKU5NtbgkNu8gr+M=
=sxRR
-----END PGP SIGNATURE-----

--uZ3hkaAS1mZxFaxD--