2022/01/28

[Python] Mac環境 URLError CERTIFICATE_VERIFY_FAILED

 比起寫教學文章,我發現我都是遇到這種莫名其妙的Bug才會出來發文

目前是覺得自己有能力寫k6的教學了,之後來動工吧

最近想學Pytest這個測試框架

用的工具當然是熟悉的Selenium

但明明之前也用過unittest + selenium,開新的.py檔後爆出以下的問題

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)>

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py:1349: URLError

Scraping: SSL: CERTIFICATE_VERIFY_FAILED error for http://en.wikipedia.org

Stack overflow的解答是

Once upon a time I stumbled with this issue. If you're using macOS go to Macintosh HD > Applications > Python3.6 folder (or whatever version of python you're using) > double click on "Install Certificates.command" file. :D


如果你是用Mac開發

你要打開來 "應用程式" -> "用來開發Python的版本" -> "Install Certificates.command"

這樣就可以了