Getting urllib2.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:661)> in mechanize open method

Getting urllib2.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:661)> in mechanize open method

我正在 urllib2.URLError: 调用 mechanize.browser.open('my https site').

时出错

我在网上进行了搜索,但没有任何效果。

这是我的代码:

import ssl
try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context
import mechanize
import operator
from bs4 import BeautifulSoup
import os
myBrowser = mechanize.Browser()
myBrowser.set_handle_robots(False)
myBrowser.set_handle_refresh(False)
myBrowser.open("https://uwp.puchd.ac.in/common/viewmarks.aspx")

这是我遇到的错误:

Traceback (most recent call last):
  File "C:/Users/Himanshu/Desktop/UIET Rank system.py", line 27, in <module>
    myBrowser.open("https://uwp.puchd.ac.in/common/viewmarks.aspx")
  File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 254, in open
    return self._mech_open(url_or_request, data, timeout=timeout)
  File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 284, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "C:\Python27\lib\site-packages\mechanize\_opener.py", line 195, in open
    response = urlopen(self, req, data)
  File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 352, in _open
    '_open', req)
  File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 340, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 1215, in https_open
    return self.do_open(conn_factory, req)
  File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 1160, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:661)>

Process finished with exit code 1

其他信息:

import ssl
print ssl.OPENSSL_VERSION

output>> OpenSSL 1.0.2j  26 Sep 2016

python版本

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32 

有什么方法可以绕过这个错误吗?

注:

此站点的问题不是证书验证,因为您已成功将其关闭。相反,问题是该站点仅支持不再被认为是安全的密码,即基于 3DES 和 RC4 的密码。 出于安全原因,ssl 库中的默认密码不包括这些密码。

要添加对这些密码的支持,您可以手动设置默认密码集。以下行将 DES-CBC3-SHA 设置为提供的密码。这样您就可以访问损坏的站点:

ssl._DEFAULT_CIPHERS = ('DES-CBC3-SHA')
myBrowser = mechanize.Browser()
...

请注意,您应该只对特定站点使用此设置。虽然理论上也可以为 _DEFAULT_CIPHERS 设置更大的密码集来处理所有站点,但这个特定站点还有其他问题:即使 DES-CBC3- SHA 包含在提供的密码集中,但如果在 DES-CBC3-SHA 之前提供较新的密码(如 GCM)。