本文介绍了在Python 3.2中,我可以使用http.client打开和读取HTTPS网页,但是urllib.request无法打开同一页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想用 urllib打开并阅读 https://yande.re/ 。请求,但我收到了SSL错误。我可以使用 http.client 使用以下代码打开并阅读页面:I want to open and read https://yande.re/ with urllib.request, but I'm getting an SSL error. I can open and read the page just fine using http.client with this code:import http.clientconn = http.client.HTTPSConnection('www.yande.re')conn.request('GET', 'https://yande.re/')resp = conn.getresponse()data = resp.read()但是,使用 urllib.request 的以下代码将失败:However, the following code using urllib.request fails:import urllib.requestopener = urllib.request.build_opener()resp = opener.open('https://yande.re/')data = resp.read()它给出了以下错误: ssl .SSLError:[Errno 1] _ssl.c:392:错误:1411809D:SSL例程:SSL_CHECK_SERVERHELLO_TLSEXT:tls无效的ecpointformat列表。为什么我可以用HTTPSConnection而不是opener.open打开页面?It gives me the following error: ssl.SSLError: [Errno 1] _ssl.c:392: error:1411809D:SSL routines:SSL_CHECK_SERVERHELLO_TLSEXT:tls invalid ecpointformat list. Why can I open the page with HTTPSConnection but not opener.open? 编辑:这是我的OpenSSL版本和试图打开的回溯 https://yande.re/ Here's my OpenSSL version and the traceback from trying to open https://yande.re/>>> import ssl; ssl.OPENSSL_VERSION'OpenSSL 1.0.0a 1 Jun 2010'>>> import urllib.request>>> urllib.request.urlopen('https://yande.re/')Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> urllib.request.urlopen('https://yande.re/') File "C:\Python32\lib\urllib\request.py", line 138, in urlopen return opener.open(url, data, timeout) File "C:\Python32\lib\urllib\request.py", line 369, in open response = self._open(req, data) File "C:\Python32\lib\urllib\request.py", line 387, in _open '_open', req) File "C:\Python32\lib\urllib\request.py", line 347, in _call_chain result = func(*args) File "C:\Python32\lib\urllib\request.py", line 1171, in https_open context=self._context, check_hostname=self._check_hostname) File "C:\Python32\lib\urllib\request.py", line 1138, in do_open raise URLError(err)urllib.error.URLError: <urlopen error [Errno 1] _ssl.c:392: error:1411809D:SSL routines:SSL_CHECK_SERVERHELLO_TLSEXT:tls invalid ecpointformat list>>>>推荐答案这是由于早期1.x OpenSSL椭圆曲线加密实现中的错误 。仔细查看异常的相关部分:This is due to a bug in the early 1.x OpenSSL implementation of elliptic curve cryptography. Take a closer look at the relevant part of the exception:_ssl.c:392: error:1411809D:SSL routines:SSL_CHECK_SERVERHELLO_TLSEXT:tls invalid ecpointformat list这是来自底层OpenSSL库代码的错误,这是错误处理的结果EC点格式TLS扩展。一种解决方法是使用SSLv3而不是SSLv23方法,另一种解决方法是使用密码套件规范来禁用所有ECC密码套件(我用 ALL获得了良好的结果:-ECDH ,使用 openssl ciphers 进行测试。修复是更新OpenSSL。This is an error from the underlying OpenSSL library code which is a result of mishandling the EC point format TLS extension. One workaround is to use the SSLv3 instead of SSLv23 method, the other workaround is to use a cipher suite specification which disables all ECC cipher suites (I had good results with ALL:-ECDH, use openssl ciphers for testing). The fix is to update OpenSSL. 这篇关于在Python 3.2中,我可以使用http.client打开和读取HTTPS网页,但是urllib.request无法打开同一页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-01 16:15