Active Silicon Harrier 40x IP摄像机Python脚本运行报错求助
解决Onvif Python脚本找不到devicemgmt-10.wsdl的问题
问题原因
报错[Errno 2] No such file or directory: '/wsdl\\devicemgmt-10.wsdl'是因为Valkka的DeviceManagement类默认尝试从本地路径加载WSDL文件,但路径格式错误(混合了正斜杠与反斜杠)或本地缺少该文件。C#示例能正常运行,说明摄像机的Onvif服务本身无问题,问题出在Python脚本的WSDL加载逻辑上。
解决方案
和你自定义MyDeviceIO类的思路一致,让DeviceManagement也使用Onvif官方的远程WSDL文件,避免本地路径依赖。具体修改如下:
- 自定义
MyDeviceManagement类,指定远程设备管理WSDL地址 - 替换原代码中
DeviceManagement的实例化,改用自定义类
修改后的完整代码
# Simple example showing how to send and receive VISCA commands # to the HArrier IP. # To install Valkka: https://valkka.readthedocs.io/en/latest/requirements.html from valkka.onvif import OnVif, DeviceManagement import time IP = "10.10.10.102" PORT=8000 # 自定义DeviceManagement,使用官方远程WSDL解决本地文件缺失问题 class MyDeviceManagement(OnVif): wsdl_file = "https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl" namespace = "http://www.onvif.org/ver10/device/wsdl" sub_xaddr = "Device" port = "DeviceBinding" # The deviceio.wsdl included in Valkka is missing the 'Token' element # for SendReceiveSerialCommand(). # The class below uses https://www.onvif.org/ver10/deviceio.wsdl, # which is correct. class MyDeviceIO(OnVif): wsdl_file = "https://www.onvif.org/ver10/deviceio.wsdl" namespace = "http://www.onvif.org/ver10/deviceIO/wsdl" sub_xaddr = "DeviceIO" port = "DeviceIOBinding" if __name__ == '__main__': try: # 使用自定义的MyDeviceManagement替代原DeviceManagement device_service = MyDeviceManagement( ip=IP, port=PORT, user="", password="" ) deviceIO_service = MyDeviceIO( ip=IP, port=PORT, user="", password="" ) deviceio_type_factory = deviceIO_service.zeep_client.type_factory("http://www.onvif.org/ver10/deviceIO/wsdl") ports = deviceIO_service.ws_client.GetSerialPorts() serial_token = ports[0].token zoom_tele = bytes.fromhex('81 01 04 07 02 FF') zoom_wide = bytes.fromhex('81 01 04 07 03 FF') print("Send zoom tele command") serial_data = deviceio_type_factory.SerialData(Binary=zoom_tele) resp = deviceIO_service.ws_client.SendReceiveSerialCommand(Token=serial_token, SerialData=serial_data, TimeOut='PT0M6S', DataLength='100', Delimiter='') print("Camera response: " + resp['Binary'].hex()) time.sleep(3) print("Send zoom wide command") serial_data = deviceio_type_factory.SerialData(Binary=zoom_wide) resp = deviceIO_service.ws_client.SendReceiveSerialCommand(Token=serial_token, SerialData=serial_data, TimeOut='PT0M6S', DataLength='100', Delimiter='') print("Camera response: " + resp['Binary'].hex()) except Exception as e: print(e)
额外检查
- 确保网络正常,脚本能访问Onvif官方WSDL地址;
- 确认摄像机Onvif服务端口(此处为8000)和权限配置正确;
- 验证
zeep库安装完整,可通过pip install zeep重新安装。
内容的提问来源于stack exchange,提问作者Abdullah Nasir
相关产品推荐
相关产品推荐

