您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在python 3.x中禁用ssl检查?

如何在python 3.x中禁用ssl检查?

使用urllib.request.urlopen自定义的SSL方面

import ssl
import urllib.request

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

with urllib.request.urlopen(url_string, context=ctx) as u, \
        open(file_name, 'wb') as f:
    f.write(u.read())

或者,如果您使用requestslibrary,则可能会更简单:

import requests

with open(file_name, 'wb') as f:
    resp = requests.get(url_string, verify=False)
    f.write(resp.content)
python 2022/1/1 18:38:36 有242人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶