I am getting urllib2.URLError: error while calling mechanize.browser.open('my https site').
I searched the web but nothing worked for me.
Here is my code:
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")
Here is the error I am getting:
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
Other information:
import ssl
print ssl.OPENSSL_VERSION
output>> OpenSSL 1.0.2j 26 Sep 2016
python version
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Is there any way to bypass this error?
Note:
- I want to use mechanize only, since my application is ready and it used to work a year before but now it's not working and I don't want to change the entire code again.
- I am using Pycharm on windows.
- Please try to open this webpage which I am trying to open it shows "Insecure connection" in chrome also and we need to proceed to the webpage. It might be the problem. Also, I don't have the certificate for this webpage.
- My application has nothing to do with security, so it will be perfectly fine to set SSL verification to false (I tried to do so from other posts, but it didn't work for me) or something like that. Only the goal is that application should work.