From ea5f712cb0a420e26ea6e883014159deb584c43b Mon Sep 17 00:00:00 2001 From: hong56hk Date: Thu, 26 Aug 2021 00:12:52 +0800 Subject: [PATCH] fix for using insecure flag does not work --- src/you_get/common.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/you_get/common.py b/src/you_get/common.py index 597ed45a..5aa74a20 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -343,7 +343,12 @@ def undeflate(data): # DEPRECATED in favor of get_content() def get_response(url, faker=False): logging.debug('get_response: %s' % url) - + ctx = None + if insecure: + # ignore ssl errors + ctx = ssl.create_default_context() + ctx.check_hostname = False + ctx.verify_mode = ssl.CERT_NONE # install cookies if cookies: opener = request.build_opener(request.HTTPCookieProcessor(cookies)) @@ -351,10 +356,10 @@ def get_response(url, faker=False): if faker: response = request.urlopen( - request.Request(url, headers=fake_headers), None + request.Request(url, headers=fake_headers), None, context=ctx, ) else: - response = request.urlopen(url) + response = request.urlopen(url, context=ctx) data = response.read() if response.info().get('Content-Encoding') == 'gzip':