我使用python3.7.2 urllib请求一个https url引发错误。如何解决。谢谢。
如果将https替换为http,则返回OK。但必须先使用此条件https。
import ssl
import urllib.request
if __name__ == '__main__':
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
response = urllib.request.urlopen('https://igionline.com/viewpdf.htm?itemno=LG11151502', timeout=10, context=ssl_context)
Traceback (most recent call last):
File "/home/wmh/Python-3.7.2/Lib/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/home/wmh/Python-3.7.2/Lib/http/client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/home/wmh/Python-3.7.2/Lib/http/client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/home/wmh/Python-3.7.2/Lib/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/home/wmh/Python-3.7.2/Lib/http/client.py", line 1016, in _send_output
self.send(msg)
File "/home/wmh/Python-3.7.2/Lib/http/client.py", line 956, in send
self.connect()
File "/home/wmh/Python-3.7.2/Lib/http/client.py", line 1392, in connect
server_hostname=server_hostname)
File "/home/wmh/Python-3.7.2/Lib/ssl.py", line 412, in wrap_socket
session=session
File "/home/wmh/Python-3.7.2/Lib/ssl.py", line 853, in _create
self.do_handshake()
File "/home/wmh/Python-3.7.2/Lib/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error