我正在尝试通过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)
答案 0 :(得分:0)
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()