How to solve urlopen error SSL: CERTIFICATE_VERIFY_FAILED

After installing Python 3.10 from, got the following error when running some scripts:

urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)


install certificates by double-clicking:

/Applications/Python 3.10/Install Certificates.command


Last login: Thu Sep 15 23:14:04 on ttys002
xxx@yyy ~ % /Applications/Python\ 3.10/Install\ Certificates.command ; exit;
 -- pip install --upgrade certifi
Collecting certifi
  Using cached certifi-2022.9.14-py3-none-any.whl (162 kB)
Installing collected packages: certifi
Successfully installed certifi-2022.9.14
 -- removing any existing file or link
 -- creating symlink to certifi certificate bundle
 -- setting permissions
 -- update complete

Saving session...
...copying shared history...
...saving history...truncating history files...

[Process completed]

Alternative solution found but not tested:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context