我一直在尝试使用python 3.3和请求登录网站,但我无法做到这一点。当我试图去那个页面时,我得到了未知的_ssl.c:550错误。谷歌和其他网页工作正常。
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 478, in urlopen
body=body, headers=headers)
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 285, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python33\lib\http\client.py", line 1065, in request
self._send_request(method, url, body, headers)
File "C:\Python33\lib\http\client.py", line 1103, in _send_request
self.endheaders(body)
File "C:\Python33\lib\http\client.py", line 1061, in endheaders
self._send_output(message_body)
File "C:\Python33\lib\http\client.py", line 906, in _send_output
self.send(msg)
File "C:\Python33\lib\http\client.py", line 844, in send
self.connect()
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connection.py", line 95, in connect
ssl_version=resolved_ssl_version)
File "C:\Python33\lib\site-packages\requests\packages\urllib3\util.py", line 634, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Python33\lib\ssl.py", line 245, in wrap_socket
_context=self)
File "C:\Python33\lib\ssl.py", line 345, in __init__
raise x
File "C:\Python33\lib\ssl.py", line 341, in __init__
self.do_handshake()
File "C:\Python33\lib\ssl.py", line 548, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL] unknown error (_ssl.c:550)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\adapters.py", line 324, in send
timeout=timeout
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 502, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL] unknown error (_ssl.c:550)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Tomas\Documents\Dropbox\python\web_login.py", line 8, in <module>
page = requests.get(url, verify=False)
File "C:\Python33\lib\site-packages\requests\api.py", line 55, in get
return request('get', url, **kwargs)
File "C:\Python33\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 382, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 485, in send
r = adapter.send(request, **kwargs)
File "C:\Python33\lib\site-packages\requests\adapters.py", line 379, in send
raise SSLError(e)
requests.exceptions.SSLError: [SSL] unknown error (_ssl.c:550)
这是我试过的脚本。
import requests
url = "https://klevas.vu.lt/"
page = requests.get(url, verify=False)
print (page.content)
将网址更改为https://www.klevas.vu.lt
(添加了www)会导致不同的错误:class 'socket.gaierror'>: [Errno 11004]
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 478, in urlopen
body=body, headers=headers)
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 285, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python33\lib\http\client.py", line 1065, in request
self._send_request(method, url, body, headers)
File "C:\Python33\lib\http\client.py", line 1103, in _send_request
self.endheaders(body)
File "C:\Python33\lib\http\client.py", line 1061, in endheaders
self._send_output(message_body)
File "C:\Python33\lib\http\client.py", line 906, in _send_output
self.send(msg)
File "C:\Python33\lib\http\client.py", line 844, in send
self.connect()
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connection.py", line 73, in connect
timeout=self.timeout,
File "C:\Python33\lib\socket.py", line 417, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\adapters.py", line 324, in send
timeout=timeout
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 528, in urlopen
raise MaxRetryError(self, url, e)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.klevas.vu.lt', port=443): Max retries exceeded with url: / (Caused by <class 'socket.gaierror'>: [Errno 11004] getaddrinfo failed)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Tomas\Documents\Dropbox\python\web_login.py", line 7, in <module>
page = requests.get(url, verify=False)
File "C:\Python33\lib\site-packages\requests\api.py", line 55, in get
return request('get', url, **kwargs)
File "C:\Python33\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 382, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 485, in send
r = adapter.send(request, **kwargs)
File "C:\Python33\lib\site-packages\requests\adapters.py", line 372, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.klevas.vu.lt', port=443): Max retries exceeded with url: / (Caused by <class 'socket.gaierror'>: [Errno 11004] getaddrinfo failed)
答案 0 :(得分:2)
@ sigmavirus24的含义示例:
(从链接的博客文章中可以看出,只使用了PROTOCOL_SSLv3
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl
class MyAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=ssl.PROTOCOL_SSLv3)
s = requests.Session()
s.mount('https://', MyAdapter())
print(s.get('https://klevas.vu.lt/'))
您正在与之交谈的服务器是来自oracle的应用程序服务器。在搜索它的服务器标识符时,您会获得许多开源项目的bugtrackers链接到这个错误中.-
答案 1 :(得分:1)
这似乎是openssl的一个问题,这是Python的ssl
模块所依赖的(反过来requests
所依赖的)。验证这一点的方法是使用openssl s_client
命令来检查:
~/sandbox/requests (master) openssl s_client -connect klevas.vu.lt:443
CONNECTED(00000003)
140721982121664:error:140773E8:SSL routines:SSL23_GET_SERVER_HELLO:reason(1000):s23_clnt.c:741:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 319 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---
这是我在python 2.7上测试时看到的相同错误。
此外,如果我测试第二个网址www.kleavs.vu.lt
,我会得到这个:
~/sandbox/requests (master) openssl s_client -connect www.klevas.vu.lt:443
connect: Connection refused
connect:errno=111
当我尝试通过Python 2或3上的请求请求第二个URL时,我看到了同样的事情。
这不是请求的问题,但是已经提交了类似的错误:#606(这是我提取openssl命令的地方)。
您可以尝试按照here说明确定不同版本的TLS或SSL是否会为您解决此问题,但我不确定在这种情况下它会有所帮助。
答案 2 :(得分:0)
我发现至少在Xubuntu 14.04上你需要安装这些模块才能运行代码: 一个。 python3-requests(http://github.com/kennethreitz/requests) 湾python3-urllib3(http://urllib3.readthedocs.org/en/latest)
然后我需要稍微修改一下代码: 从urllib3.poolmanager导入PoolManager 而不是 来自requests.packages.urllib3.poolmanager导入PoolManager
import requests
from requests.adapters import HTTPAdapter
from urllib3.poolmanager import PoolManager
import ssl
class MyAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=ssl.PROTOCOL_SSLv3)
s = requests.Session()
s.mount('https://', MyAdapter())
print(s.get('https://klevas.vu.lt/'))
返回
<Response [200]>