hstatus.py 文件源码

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

项目:huawei-hilink-status 作者: trick77 项目源码 文件源码
def call_api(device_ip, token, resource, xml_attribs=True):
    headers = {}
    if token is not None:
        headers = {'__RequestVerificationToken': token}
    try:
        r = requests.get(url='http://' + device_ip + resource, headers=headers, allow_redirects=False, timeout=(2.0,2.0))
    except requests.exceptions.RequestException as e:
        print ("Error: "+str(e))
        return False;

    if r.status_code == 200:
        d = xmltodict.parse(r.text, xml_attribs=xml_attribs)
        if 'error' in d:
            raise Exception('Received error code ' + d['error']['code'] + ' for URL ' + r.url)
        return d            
    else:
      raise Exception('Received status code ' + str(r.status_code) + ' for URL ' + r.url)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号