我一直试图使用python3.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)将url更改为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)发布于 2014-01-01 23:01:46
示例:@sigmavirus24 24的意思是:(它是从链接的博客文章字面上取下来的,只使用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的应用服务器。在搜索它的服务器标识符时,您会得到指向许多开源项目的bug跟踪器的链接。
发布于 2013-12-31 01:39:34
这似乎是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
---这是我在python2.7上测试时看到的相同错误。
此外,如果我测试第二个url 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时看到的情况是一样的。
这并不是请求的问题,但类似的but已经被归档:#606 (这就是我使用openssl命令的地方)。
您可以尝试按照这里的说明来确定不同版本的TLS或SSL是否会为您解决这个问题,但我不确定它在这种情况下是否会有所帮助。
发布于 2014-09-29 19:49:23
我发现,至少在Xubuntu14.04中,您需要安装这些模块才能运行代码: a. python3 3-requests (http://github.com/kennethreitz/requests) b. python3-urllib 3 (http://urllib3.readthedocs.org/en/latest)
然后,我需要稍微修改代码:从urllib3.池管理器导入PoolManager,而不是从requests.Packages.urllib3.info.gov.hk管理器导入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]>https://stackoverflow.com/questions/20849734
复制相似问题