gpt4 book ai didi

python - 如何在 python 中禁用 http.client.HTTPSConnection 类的 ssl 验证?

转载 作者:太空宇宙 更新时间:2023-11-03 12:36:32 34 4
gpt4 key购买 nike

HTTP PROTOCOL CLIENT的官方文档中

class http.client.HTTPSConnection(host, port=None, key_file=None, cert_file=None, [timeout, ]source_address=None, *, context=None, check_hostname=None)

A subclass of HTTPConnection that uses SSL for communication with secure servers. Default port is 443. If context is specified, it must be a ssl.SSLContext instance describing the various SSL options.

是否有任何选项可以像 python 请求库一样禁用 ssl 验证作为 verify=fasle

由于某些原因,我不能使用 HTTPConnection 类,这将是一个直接的解决方案。我必须使用 HTTPSConnection 并使用

HTTPConnection.putrequest()

不通过ssl验证发送请求。

最佳答案

在创建 https 连接时,请确保按如下方式传递上下文参数

import http.client
import ssl

conn = http.client.HTTPSConnection(
HOSTNAME,
context = ssl._create_unverified_context()
)

关于python - 如何在 python 中禁用 http.client.HTTPSConnection 类的 ssl 验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48908044/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com