{"id":3714,"date":"2020-05-20T10:52:37","date_gmt":"2020-05-20T02:52:37","guid":{"rendered":"https:\/\/www.ookangzheng.com\/?p=3714"},"modified":"2020-05-24T15:57:57","modified_gmt":"2020-05-24T07:57:57","slug":"python3-on-mac-ssl-certificate-verify-failed","status":"publish","type":"post","link":"https:\/\/www.ookangzheng.com\/python3-on-mac-ssl-certificate-verify-failed\/","title":{"rendered":"Python3 on Mac SSL certificate verify failed"},"content":{"rendered":"\n

Lib: json, urllib.request<\/p>\n\n\n\n

Sample code<\/p>\n\n\n\n

import json\nfrom urllib.request import urlopen\n\nurl = \"https:\/\/api.github.com\/\"\n\ndef get(url, object_hook=None):\n    with urlopen(url) as resource:\n        return json.load(resource, object_hook=object_hook)\n\ndata = get(url)\nprint(data)<\/code><\/pre>\n\n\n\n

Error<\/p>\n\n\n\n

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)><\/code><\/pre>\n\n\n\n

Solution via Install Certificate.command<\/em><\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Solution via pip upgrade<\/p>\n\n\n\n

pip install --upgrade certifi<\/code><\/pre>\n\n\n\n

Solution workaround in code<\/p>\n\n\n\n

# Use undefinded SSL\n\nimport ssl\nssl._create_default_https_context = ssl._create_unverified_context<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Lib: json, urllib.request Sample code Error Solution via Install Certificate.command Solution via pip upgrade Solution workaround in code<\/p>\n","protected":false},"author":1,"featured_media":3748,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88,37,33],"tags":[],"class_list":["post-3714","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apps","category-linux","category-front-end"],"_links":{"self":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/3714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/comments?post=3714"}],"version-history":[{"count":0,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/3714\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/media\/3748"}],"wp:attachment":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/media?parent=3714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/categories?post=3714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/tags?post=3714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}