urllib getting SSL certificate info

Fredrik Lundh fredrik at pythonware.com
Sat Aug 16 05:16:14 EDT 2008


Ghirai wrote:

> Using urllib, is there any way i could access some info about the SSL 
> certificate (when opening a https url)?
> 
> I'm really interested in the fingerprint.
> 
> I haven't been able to find anything so far.

you can get some info via (undocumented?) attributes on the file handle:

 >>> import urllib
 >>> f = urllib.urlopen("https://mail.google.com/")
 >>> f.fp
<httplib.SSLFile instance at 0x00CE2508>
['issuer', 'read', 'server', 'write']
 >>> f.fp._ssl.issuer()
'/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA'
 >>> f.fp._ssl.server()
'/C=US/ST=California/L=Mountain View/O=Google Inc/CN=mail.google.com'

</F>




More information about the Python-list mailing list