Urllib.urlopen()在一台机器上使用Python 2.6.6在SSLv3 URL上工作,但在另一台机器上不在2.6.7/2.7.2上工作

jwa*_*yne 10 python ssl https urllib urlopen

在这一天花了很多时间,我真的在我的智慧结束.我有一台机器"A"安装了Python 2.6.6/2.7.2,另一台机器"B"安装了Python 2.6.7/2.7.2.

在机器A上,我可以urllib2.urlopen('https://fed.princeton.edu')使用Python 2.6.6 获得SSLv3加密的网站,但不能使用2.7.2.

在机器B上,我无法使用Python版本获得该网站.

由于无法得到,我的意思是我得到错误:

Traceback:
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django_cas-2.0.3-py2.7.egg/django_cas/views.py" in login
  78.         user = auth.authenticate(ticket=ticket, service=service)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/contrib/auth/__init__.py" in authenticate
  55.             user = backend.authenticate(**credentials)
File "/usr/local/lib/python2.7/dist-packages/django_cas-2.0.3-py2.7.egg/django_cas/backends.py" in authenticate
  72.         username = _verify(ticket, service)
File "/usr/local/lib/python2.7/dist-packages/django_cas-2.0.3-py2.7.egg/django_cas/backends.py" in _verify_cas2
  46.     page = urlopen(url)
File "/usr/lib/python2.7/urllib.py" in urlopen
  84.         return opener.open(url)
File "/usr/lib/python2.7/urllib.py" in open
  205.                 return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py" in open_https
  435.             h.endheaders(data)
File "/usr/lib/python2.7/httplib.py" in endheaders
  954.         self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py" in _send_output
  814.         self.send(msg)
File "/usr/lib/python2.7/httplib.py" in send
  776.                 self.connect()
File "/usr/lib/python2.7/httplib.py" in connect
  1161.             self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File "/usr/lib/python2.7/ssl.py" in wrap_socket
  372.                      ciphers=ciphers)
File "/usr/lib/python2.7/ssl.py" in __init__
  134.                 self.do_handshake()
File "/usr/lib/python2.7/ssl.py" in do_handshake
  296.         self._sslobj.do_handshake()

Exception Type: IOError at /login
Exception Value: [Errno socket error] [Errno 1] _ssl.c:503: error:140773F2:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert unexpected message
Run Code Online (Sandbox Code Playgroud)

首先,我很困惑,在早期的Python版本上工作的东西在机器A的后期不起作用.我也很困惑,2.6.6上工作的东西在2.6.7上不起作用(虽然在不同的机器上).为什么会这样?

现在我不确定Python的配置是否完全相同,但是import _ssl并且import httplib; httplib.HTTPSConnection适用于两台机器上的所有版本.我也试着curl -v https://fed.princeton.eduopenssl fed.princeton.edu:https在两台机器上,这些命令所有工作.

我也做了一些研究,发现如何使用urllib2来获取一个使用SSLv3加密的网页,其中作者似乎已经放弃了urllib for libCurl(我宁愿没有,因为我使用的是django-cas,它使用的是urllib而且我不想过多地使用那些代码.


注意:我刚刚找到http://bugs.python.org/issue11220,最后一篇文章的解决方案允许我使用urlopen来打开网站.但是我如何使用他们的解决方案(似乎是使用urllib2.install_opener(urllib2.build_opener(HTTPSHandlerV3()))?)来解决django-cas中的urlopen()?

jwa*_*yne 6

经过一些实验,我刚接受Python 2.6.6没问题,但2.6.7+有这个错误,无法通过获取SSLv3加密的页面urllib.urlopen().

我简单地使用解决我的问题urllib2.install_opener计谋http://bugs.python.org/issue11220,并改装成django_cas使这个揭幕战之前,任何安装了urlopen()电话.