python 调用httplib 访问系统 调用Pisa协议

来源:互联网 发布:板式家具下料软件 编辑:程序博客网 时间:2024/06/18 03:52

 

        conn = httplib.HTTPConnection(ip + ":80")          headers = {"Content-type": "application/xml",  "Accept": "text/plain", "Authorization": "Basic YWRtaW46MTIzNDU=",'x-  requested-with':'XMLHttpRequest'}          conn.request("GET", "具体的协议接口", "", headers)          response = conn.getresponse()          print(str(response.status) + " " + str(response.reason))        data = response.read()                  dom = lxml.etree.fromstring(str(data))        str2="//n:RS485Lane[%s]/n:carHighSpeed"%lane_no#异常超速           for node in dom.xpath(str2, namespaces={'n':'http://www.hikvision.com/ver10/XMLSchema'}):                print (node.text )             CarHighSpeed=node.text


header部分,有个Authorization 这个是验证相关的,如果没有这个则登录设备失败

 

lxml主要用来处理接口返回的xml格式的文件,使用了xpath的方式,来获取对应的节点,进而获取到对应的值。

 

有个namespace的问题,写xpath的时候,要指明一下,具体的xpath路径也要带上该空间

0 0