error code

Mark McEahern marklists at mceahern.com
Wed Jul 24 11:59:54 EDT 2002


> In your example you write the Exception code .
>
> for example :
> try :
>     server = smtplib.SMTP('XXXXXXX')
> except :
>     print "error : %s --> %s " % ( sys.exc_value , sys.exc_type)
>
> If I put a bad host , I have the error : "error : host not found -->
> socket.error"
>
> I suppose that the error "host not found" have a caracteristic number .
> how can I get it ?

As Alex pointed out, not all Exceptions have an error number or code
associated with them.

Notice how much easier it is to help you, by the way, when you post a real
live sample of code.  <wink>

In the case of the above, I would write that:

try:
  server = smtplib.SMTP('XXXXXXX')
except Exception, e:
  ...

Then, interactively, just to figure this out, I'd do this:

  print dir(e)

Hmm, there's an args attribute there.  What's in it?

  print e.args

Result:

  (7, 'getaddrinfo failed')

So, in this caes, e.args is a tuple.  7 might be what you're looking for.
But I haven't looked into the smtplib module to see whether it is.  But
that's the wonderful thing about open source--you can.  <wink>

Cheers,

// mark

-





More information about the Python-list mailing list