Ambari启用认证,发送restful请求报错[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

来源:互联网 发布:网络大电影编剧收费 编辑:程序博客网 时间:2024/05/01 05:26

个人采用python代码实现:

解决方法:

#私有方法,封装的目的是为了捕获异常    def __sendRequest(self, req, desc):        try :            context = ssl._create_unverified_context()            res = urllib2.urlopen(req, context = context)  ##发送请求,接受反馈的信息        #HTTPError是URLError的子类        except urllib2.URLError, e:            if hasattr(e, 'code'):                # Only HTTPError has code attribute.                print ('The server couldn\'t fulfill the request. %s failed, error code:%s, reason:%s' % (desc, e.code, e.reason))            elif hasattr(e, 'reason'):                # HTTPError and URLError all have reason attribute.                print ('We failed to reach a server. %s failed, reason:%s' % (desc, e.reason))            return False, None        else:            # everything is fine            res = res.read()  # 读取反馈的内容            print res            return True, res

记住:

如果有HEADER头域的Accept字段值,需设置为:
"Accept":"*/*"

阅读全文
0 0