url_request.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:Belati 作者: aancw 项目源码 文件源码
def ssl_checker(self, domain):
        domain_fix = "https://{}".format(domain)

        try:
            # Skip SSL Verification Check!
            # https://stackoverflow.com/questions/27835619/ssl-certificate-verify-failed-error
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)  # Only for gangstars
            data = urllib2.urlopen("https://{}".format(domain), timeout=25, context=gcontext)
            if "ERROR" in data or "Errno" in data:
                domain_fix = "http://{}".format(domain)
        except urllib2.HTTPError, e:
            pass
        except urllib2.URLError, e:
            domain_fix = "http://{}".format(domain)
        except ssl.SSLError as e:
            domain_fix = "http://{}".format(domain)
        except httplib.BadStatusLine:
            domain_fix = "http://{}".format(domain)

        return domain_fix
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号