SSL: CERTIFICATE_VERIFY_FAILED error with python3 on macOS 10.15

后端 未结 5 2185
一向
一向 2021-02-06 00:01

/usr/bin/python3 from Xcode/CLT on macOS 10.15 (DB6/PB5 at the moment, with Xcode 11 beta 6) fails with SSL: CERTIFICATE_VERIFY_FAILED for all HTTPS re

5条回答
  •  不要未来只要你来
    2021-02-06 00:46

    According to this GitHub issue, Apple refused to fix this:

    The problem behaves as intended.

    certifi is a third-party module, not part of Python itself.

    urllib is a low-level library. It can handle SSL, but you must explicitly set up the SSL context with a cafile.

    Try the following instead:

    pip3 install requests
    python3 -c 'import requests; print(requests.get("https://apple.com").text)'
    

    If you only want to get cacert.pem, you can use pip3 install certifi, but you must still explicitly pass cafile to urllib.

    So my solution is simply using Requests instead. This is supported and future proof.

提交回复
热议问题