导入 ssl 包
import ssl
创建context,
context = ssl._create_unverified_context()
把context添加到请求,
from urllib import request
import ssl
context = ssl._create_unverified_context()
with request.urlopen('https://api.douban.com/v2/book/2129650', context=context)as f:
data = f.read()
print('Status:', f.status, f.reason)
for k, vin f.getheaders():
print('%s: %s' % (k, v))
print('Data:', data.decode('utf-8'))