如何解决“不良握手"问题?利用python请求时的SSLErrors [英] How to fix "bad handshake" SSLErrors when utilizing python requests

查看:155
本文介绍了如何解决“不良握手"问题?利用python请求时的SSLErrors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问BambooHR API(此处的文档 ),但出现以下错误

I'm trying to get access to the BambooHR API (documentation here), but I receive the following error

    params = {
        'user': username,
        'password': password,
        'api_token': api_key}
    url = 'https://api.bamboohr.com/api/gateway.php/company/v1/login'
    r = requests.get(url, params=params)

错误:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1580, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 964, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/chriscruz/Dropbox/PycharmProjects/082716_r2/Shippy/API/bamboo_api2.py", line 31, in <module>
    BambooFunctions().login()
  File "/Users/chriscruz/Dropbox/PycharmProjects/082716_r2/Shippy/API/bamboo_api2.py", line 26, in login
    r = requests.get(url, params=params, auth=HTTPBasicAuth(api_key, 'api_token'))
  File "/Library/Python/2.7/site-packages/requests/api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/adapters.py", line 497, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'unknown protocol')],)",)

我不确定这是什么原因,因为我已经重新安装了OpenSSL,请求,并且不确定如何解决此问题.

I'm unsure what this is caused by as I've re-installed OpenSSL, Requests, and not sure how to fix this issue.

推荐答案

您尝试通过设置verify = False进行尝试,如果您使用的是自签名证书,请使用此选项.

You try by setting verify=False, use this option if you are using self-signed certificates.

r = requests.get(url, params=params, verify=False)

更多信息 http://docs.python -requests.org/en/master/user/advanced/#ssl-cert-verification

这篇关于如何解决“不良握手"问题?利用python请求时的SSLErrors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆