導(dǎo)入 ssl 包
import ssl
創(chuàng)建context,
context = ssl._create_unverified_context()
把context添加到請(qǐng)求撞蚕,
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'))