Tou*_*sah 1 python parameters ssl-certificate httplib2
我想知道 httplib2.Http 类的 request 方法采用什么参数。我正在尝试使用一个简单的 get 方法,但似乎我使用的 url 提供了一个需要验证的证书,因为我收到 SSL3_GET_SERVER_CERTIFICATE 错误。这就是为什么我想知道使用 httplib2 库我们是否可以告诉我们的请求忽略证书验证(如urllib.request 的不可验证参数)。这是我的代码:
import httplib2
h = httplib2.Http(".cache")
h.credentials_add(username, password)
resp, content = h.request(url, "GET")
Run Code Online (Sandbox Code Playgroud)
您可以使用disable_ssl_certificate_validation忽略证书验证。请检查下面的示例。但是,由于以下错误,它无法与Python 3.x一起使用。因此,您需要Python33\Lib\site-packages\httplib2\__init__.py按照此问题评论中的建议进行更新。
当disable_ssl_certificate_validation = True时,HTTPS请求不起作用
import httplib2
h = httplib2.Http(".cache", disable_ssl_certificate_validation=True)
resp, content = h.request("https://github.com/", "GET")
Run Code Online (Sandbox Code Playgroud)
Python 3.x 补丁:
diff --git a/__init__.py b/__init__.py
index 65f90ac..4495994 100644
--- a/__init__.py
+++ b/__init__.py
@@ -823,10 +823,13 @@ class HTTPSConnectionWithTimeout(http.client.HTTPSConnection):
context.load_cert_chain(cert_file, key_file)
if ca_certs:
context.load_verify_locations(ca_certs)
+ check_hostname = True
+ if disable_ssl_certificate_validation:
+ check_hostname = False
http.client.HTTPSConnection.__init__(
self, host, port=port, key_file=key_file,
cert_file=cert_file, timeout=timeout, context=context,
- check_hostname=True)
+ check_hostname=check_hostname)
SCHEME_TO_CONNECTION = {
Run Code Online (Sandbox Code Playgroud)