Я получаю SSLError
, когда пытаюсь очистить сайт BeautifulSoup4
, но я использую urllib
, чтобы просто открыть ссылку. Я получил его для работы на Java с JSoup
(скребок для Java), создав сертификат на веб-сайте, который я пытаюсь очистить от here. Можно ли использовать этот сертификат в Python? Файл, который был сгенерирован, был вызван jssecacerts, но переименован в cacerts.Ошибка SSL с urllib
Это код, я использую:
def open(url, postdata=None):
if postdata is 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)
Ошибка:
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 the above exception, another 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 the above exception, another 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)>
StackTrace или фактическое сообщение об ошибке будет полезно. И так же, как побочная заметка: обычно считается неправильной практикой назначать параметры метода внутри указанного метода. – Dave
Попробуйте выполнить следующие действия: http://stackoverflow.com/a/28052583/1102395 – Samar