Python - SSLV3_ALERT_HANDSHAKE_FAILURE,这是一个密码还是一个证书问题?

时间:2017-08-21 12:25:58

标签: python ssl

我正在尝试通过python请求API执行https url,但是我收到错误:

  File "<console>", line 5, in <module>
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 513, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 623, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:579)

我认为这可能是一个不受信任的警告,因此我使用了

requests.packages.urllib3.disable_warnings()

但这没有用,进一步搜索表明它可能与密码有关?

我的代码如下:

import requests
username="ncm"
password="*****"
headers={'content-type':'application/json'}
response = requests.get('https://10.55.244.2/level/15/exec/-/traceroute/10.50.0.1/source/vlan/5/CR',
                        verify=False,
                        auth=(username, password),
                        headers=headers,
                        timeout=4)

颁发证书 certificate info

1 个答案:

答案 0 :(得分:0)

经过一些搜索后我发现使用urlib2工作,下面的代码可以正常工作

import urllib2, base64
request = urllib2.Request('https://yoururl')
base64string = base64.b64encode('%s:%s' % (username, password))
request.add_header("Authorization", "Basic %s" % base64string)   
result = urllib2.urlopen(request).read()