fensnote
调试一个新的海康相机PTZ控制,使用onvif控制时报如下错误:
soap_call___tptz__ContinuousMove ret: 12 error: 12
这个错误是SOAP执行失败,这里也看不到太多信息,只有把Onvif的DEBUG日志打开,打开方法是编译的时候加上编译选项:-DSOAP_DEBUG
再次执行时,查看RECV.log文件里的日志如下(日志比较多,这里只取了报错的这部分):
HTTP/1.1 400 Bad Request Date: Sat, 30 Oct 2021 10:33:49 GMT X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Content-Length: 2371 Connection: close Content-Type: application/soap+xml; charset=utf-8 <?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tst="http://www.onvif.org/ver10/storage/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:dn="http://www.onvif.org/ver10/network/wsdl" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl" xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12" xmlns:http="http://schemas.xmlsoap.org/wsdl/http" xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsadis="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2" xmlns:wsrf-rw="http://docs.oasis-open.org/wsrf/rw-2" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:tnshik="http://www.hikvision.com/2011/event/topics" xmlns:hikwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl" xmlns:hikxsd="http://www.onvifext.com/onvif/ext/ver10/schema" xmlns:tas="http://www.onvif.org/ver10/advancedsecurity/wsdl" xmlns:tr2="http://www.onvif.org/ver20/media/wsdl" xmlns:axt="http://www.onvif.org/ver20/analytics"><env:Body><env:Fault><env:Code><env:Value>env:Sender</env:Value> <env:Subcode><env:Value>ter:NotAuthorized</env:Value> </env:Subcode> </env:Code> <env:Reason><env:Text xml:lang="en">The action requested requires authorization and the sender is not authorized</env:Text> </env:Reason> </env:Fault> </env:Body> </env:Envelope>
可以看出提示的是权限问题,但是代码里是有鉴权的,获取Profile时已经执行成功了,这不是代码鉴权的问题。后来发现是admin这个用户的权限问题,权限不够,不是管理员权限,而是视频用户!
这个只需要在海康摄像机的内置web管理页面配置一下即可:
这里选择为管理员,然后保存即可。
大华摄像机配置
大华的摄像机需要在onvif里加一个用户,这个用户需要属于admin组:
用户组一定要选admin,不然云台控制不了