fix for using insecure flag does not work

This commit is contained in:
hong56hk 2021-08-26 00:12:52 +08:00
parent 5498c377ff
commit ea5f712cb0

View File

@ -343,7 +343,12 @@ def undeflate(data):
# DEPRECATED in favor of get_content() # DEPRECATED in favor of get_content()
def get_response(url, faker=False): def get_response(url, faker=False):
logging.debug('get_response: %s' % url) 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 # install cookies
if cookies: if cookies:
opener = request.build_opener(request.HTTPCookieProcessor(cookies)) opener = request.build_opener(request.HTTPCookieProcessor(cookies))
@ -351,10 +356,10 @@ def get_response(url, faker=False):
if faker: if faker:
response = request.urlopen( response = request.urlopen(
request.Request(url, headers=fake_headers), None request.Request(url, headers=fake_headers), None, context=ctx,
) )
else: else:
response = request.urlopen(url) response = request.urlopen(url, context=ctx)
data = response.read() data = response.read()
if response.info().get('Content-Encoding') == 'gzip': if response.info().get('Content-Encoding') == 'gzip':