Tuesday, 15 May 2012

ssl - Adding timeout while fetching server certs via python -



ssl - Adding timeout while fetching server certs via python -

i trying fetch list of server certificates , using python standard ssl library accomplish this. how doing it:

import ssl socket import * urls = [i.strip().lower() in open("urls.txt")] urls in url: try: print ssl.get_server_certificate((url, 443)) except error: print "no connection"

however urls,there connectivity issues , connection times out.however waits default ssl timeout value(which quite long) before timing out.how specify timeout in ssl.get_server_certificate method ? have specified timeouts sockets before clueless how method

from docs:

ssl sockets provide next methods of socket objects: gettimeout(), settimeout(), setblocking()

so should simple as:

import ssl socket import * settimeout(10) urls = [i.strip().lower() in open("urls.txt")] urls in url: try: print ssl.get_server_certificate((url, 443)) except (error, timeout) err: print "no connection: {0}".format(err)

python ssl ssl-certificate

No comments:

Post a Comment