fix problem with ssl certificate (on mac)

fixes error "unable to get local issuer certificate (_ssl.c:1123)>)"
pull/37/head
erlenkh 2021-03-20 14:25:16 +01:00 committed by GitHub
parent c875389e9a
commit 757e6d496e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -13,6 +13,8 @@ import urllib.error
import urllib.parse import urllib.parse
import urllib.request import urllib.request
import webbrowser import webbrowser
import certifi
import ssl
logging.basicConfig(level=20, datefmt='%I:%M:%S', format='[%(asctime)s] %(message)s') logging.basicConfig(level=20, datefmt='%I:%M:%S', format='[%(asctime)s] %(message)s')
@ -36,7 +38,8 @@ class SpotifyAPI:
try: try:
req = urllib.request.Request(url) req = urllib.request.Request(url)
req.add_header('Authorization', 'Bearer ' + self._auth) req.add_header('Authorization', 'Bearer ' + self._auth)
res = urllib.request.urlopen(req) context = ssl.create_default_context(cafile=certifi.where())
res = urllib.request.urlopen(req, context=context)
reader = codecs.getreader('utf-8') reader = codecs.getreader('utf-8')
return json.load(reader(res)) return json.load(reader(res))
except Exception as err: except Exception as err: