cmxutil.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:sample-code-cmx 作者: CiscoDevNet 项目源码 文件源码
def get_json_response(server, api, username, password):
        """
        Returns the response from the URL specified
        """
        try:
            # lib opener
            response = {}
            context = ssl._create_unverified_context()
            conn = HTTPSConnection(server, context=context)
            auth = str.encode("%s:%s" % (username, password))
            user_and_pass = b64encode(auth).decode("ascii")
            headers = {'Authorization': 'Basic %s' % user_and_pass, "Accept": 'application/json'}
            conn.request('GET', api, headers=headers)
            res = conn.getresponse()
            bit_data = res.read()
            string_data = bit_data.decode(encoding='UTF-8')
            response['data'] = string_data
            response['status'] = 200
        except:
            print("--Unexpected error:", sys.exc_info()[1])
            response['data'] = sys.exc_info()[1]
            response['status'] = 400

        return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号