我正在尝试使用ssl创建连接。_create_unverified_context作为context:
conn = http.client.HTTPSConnection('www.google.com', context=ssl._create_unverified_context)
conn.request()
res = conn.getresponse()
data = res.read()
conn.close()
我得到的是这个错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-31-c21b1071d0e6> in <module>
----> 1 conn = http.client.HTTPSConnection('www.google.com', context=ssl._create_unverified_context)
2 conn.request()
3 res = conn.getresponse()
4 data = res.read()
5 conn.close()
C:ProgramDataMiniconda3libhttpclient.py in __init__(self, host, port, key_file, cert_file, timeout, source_address, context, check_hostname, blocksize)
1396 if context.post_handshake_auth is not None:
1397 context.post_handshake_auth = True
-> 1398 will_verify = context.verify_mode != ssl.CERT_NONE
1399 if check_hostname is None:
1400 check_hostname = context.check_hostname
AttributeError: 'function' object has no attribute 'verify_mode'
下面的代码片段对我来说很好:
import http.client
import ssl
conn = http.client.HTTPSConnection('www.google.com', context=ssl._create_unverified_context)