I would like to know the redirected address when I accessed the Https address. - SSL: CERTIFICATE_VERIFY_FAILED Error

Asked 2 years ago, Updated 2 years ago, 118 views

There are about 300 https addresses listed. It will be redirected to a different address as soon as I access it, so how can I get that address?

In the case of http, it is said that the following can be done

import urllib2

def get_redirected_url(url):
    opener = urllib2.build_opener(urllib2.HTTPRedirectHandler)
    request = opener.open(url)
    return request.url

print get_redirected_url ("http://address")

It's https urlib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed ().

python redirect urllib

2022-09-22 22:01

1 Answers

It's a self-answer.

import urllib
import ssl

def get_redirected_url(url):
    context = ssl._create_unverified_context()
    return urllib.urlopen(url, context=context)

print get_redirected_url ("https://address").geturl()

It's working like this.


2022-09-22 22:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.