nexB/aboutcode-toolkit

SSL exception when doing --fetch-license

chinyeungli opened this issue · 2 comments

<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>

Some users experience the above SSL expcetion when going thru the valid_api_url function
Below is the modified valid_api_function to print the exception

def valid_api_url(api_url):
    try:
        request = Request(api_url)
        # This will always goes to exception as no key are provided.
        # The purpose of this code is to validate the provided api_url is correct
        urlopen(request)
        return True
    except HTTPError as http_e:
        # The 403 error code is refer to "Authentication credentials were not provided.".
        # This is correct as no key are provided.
        if http_e.code == 403:
            return True
    except Exception as e:
        import sys
        print(str(e))
	sys.exit(1)
    return False

It’s a known issue on MacOS and Python3.6 for example, a solution is to run: sudo /Applications/Python\ 3.6/Install\ Certificates.command to upgrade the outdated certificates

Add documentation for macOS user to upgrade the outdated certificates
https://aboutcode-toolkit.readthedocs.io/en/latest/home.html#installation