java - SSL error with urllib -


i'm getting sslerror when i'm trying scrape website beautifulsoup4 i'm using urllib open link. got work in java jsoup (scraper java) generating certificate website i'm trying scrape here. possible use certificate in python? file generated called jssecacerts renamed cacerts.

this code i'm using:

def open(url, postdata=none):     if postdata not none:         postdata = urlencode(postdata)         postdata = postdata.encode('utf-8')     return browser.open(url, postdata).read()  def login(i):     cj = http.cookiejar.cookiejar()     global browser     browser = urllib.request.build_opener(urllib.request.httpcookieprocessor(cj))      post = {'timezoneoffset': timezoneoffset,             'userid': userid,             'pwd': pwd,             }      open(login_url, post) 

the error:

process process-1: traceback (most recent call last): process process-2: traceback (most recent call last):   file "c:\python34\lib\urllib\request.py", line 1182, in do_open     h.request(req.get_method(), req.selector, req.data, headers)   file "c:\python34\lib\urllib\request.py", line 1182, in do_open     h.request(req.get_method(), req.selector, req.data, headers)   file "c:\python34\lib\http\client.py", line 1088, in request     self._send_request(method, url, body, headers)   file "c:\python34\lib\http\client.py", line 1088, in request     self._send_request(method, url, body, headers)   file "c:\python34\lib\http\client.py", line 1126, in _send_request     self.endheaders(body)   file "c:\python34\lib\http\client.py", line 1126, in _send_request     self.endheaders(body)   file "c:\python34\lib\http\client.py", line 1084, in endheaders     self._send_output(message_body)   file "c:\python34\lib\http\client.py", line 922, in _send_output     self.send(msg)   file "c:\python34\lib\http\client.py", line 1084, in endheaders     self._send_output(message_body)   file "c:\python34\lib\http\client.py", line 857, in send     self.connect()   file "c:\python34\lib\http\client.py", line 1231, in connect     server_hostname=server_hostname)   file "c:\python34\lib\http\client.py", line 922, in _send_output     self.send(msg)   file "c:\python34\lib\http\client.py", line 857, in send     self.connect()   file "c:\python34\lib\http\client.py", line 1231, in connect     server_hostname=server_hostname)   file "c:\python34\lib\ssl.py", line 365, in wrap_socket     _context=self)   file "c:\python34\lib\ssl.py", line 583, in __init__     self.do_handshake()   file "c:\python34\lib\ssl.py", line 810, in do_handshake     self._sslobj.do_handshake() ssl.sslerror: [ssl: certificate_verify_failed] certificate verify failed     (_ssl.c:600)  during handling of above exception, exception occurred:  traceback (most recent call last):   file "c:\python34\lib\ssl.py", line 365, in wrap_socket     _context=self)   file "c:\python34\lib\ssl.py", line 583, in __init__     self.do_handshake()   file "c:\python34\lib\ssl.py", line 810, in do_handshake     self._sslobj.do_handshake() ssl.sslerror: [ssl: certificate_verify_failed] certificate verify failed (_ssl.c:600)  during handling of above exception, exception occurred:  traceback (most recent call last):   file "c:\python34\lib\multiprocessing\process.py", line 254, in _bootstrap     self.run()   file "c:\python34\lib\multiprocessing\process.py", line 93, in run     self._target(*self._args, **self._kwargs)   file "c:\python34\lib\multiprocessing\process.py", line 254, in _bootstrap     self.run()   file "c:\python34\lib\multiprocessing\process.py", line 93, in run     self._target(*self._args, **self._kwargs)   file "e:\eng_cfr_ps_map\eng_cfr_map.py", line 159, in main     login(i)   file "e:\eng_cfr_ps_map\eng_cfr_map.py", line 159, in main     login(i)   file "e:\eng_cfr_ps_map\eng_cfr_map.py", line 109, in login     open(login_url, post)   file "e:\eng_cfr_ps_map\eng_cfr_map.py", line 109, in login     open(login_url, post)   file "e:\eng_cfr_ps_map\eng_cfr_map.py", line 33, in open     return browser.open(url, postdata).read()   file "c:\python34\lib\urllib\request.py", line 463, in open     response = self._open(req, data)   file "c:\python34\lib\urllib\request.py", line 481, in _open     '_open', req)   file "e:\eng_cfr_ps_map\eng_cfr_map.py", line 33, in open     return browser.open(url, postdata).read()   file "c:\python34\lib\urllib\request.py", line 441, in _call_chain     result = func(*args)   file "c:\python34\lib\urllib\request.py", line 463, in open     response = self._open(req, data)   file "c:\python34\lib\urllib\request.py", line 1225, in https_open     context=self._context, check_hostname=self._check_hostname)   file "c:\python34\lib\urllib\request.py", line 1184, in do_open     raise urlerror(err)   file "c:\python34\lib\urllib\request.py", line 481, in _open     '_open', req) urllib.error.urlerror: <urlopen error [ssl: certificate_verify_failed]     certificate verify failed (_ssl.c:600)>   file "c:\python34\lib\urllib\request.py", line 441, in _call_chain     result = func(*args)   file "c:\python34\lib\urllib\request.py", line 1225, in https_open     context=self._context, check_hostname=self._check_hostname)   file "c:\python34\lib\urllib\request.py", line 1184, in do_open     raise urlerror(err) urllib.error.urlerror: <urlopen error [ssl: certificate_verify_failed]     certificate verify failed (_ssl.c:600)> 

can proxy related. if you're behind proxy, try setting system environment variables http_proxy , https_proxy. modifying cacerts should done part of suggested.

proxy http_proxy=http://proxy.mycompany.com:80

etc


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -