Python ONVIF GotoPreset无法设置全局移动速度



我正在尝试设置名为";Preset001";有一个定义良好的速度,但我不能,因为我在控制台上得到以下错误:

My camera's hostname: MYCAM
gotoPreset:
{
'ProfileToken': 'MainStreamProfileToken',
'PresetToken': 'Preset001',
'Speed': 0.1
}
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/onvif/client.py", line 140, in call
ret = func(**params)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/proxy.py", line 46, in __call__
return self._proxy._binding.send(
File "/home/pi/.local/lib/python3.9/site-packages/zeep/wsdl/bindings/soap.py", line 123, in send
envelope, http_headers = self._create(
File "/home/pi/.local/lib/python3.9/site-packages/zeep/wsdl/bindings/soap.py", line 73, in _create
serialized = operation_obj.create(*args, **kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/wsdl/definitions.py", line 222, in create
return self.input.serialize(*args, **kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/wsdl/messages/soap.py", line 79, in serialize
self.body.render(body, body_value)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 232, in render
self._render_value_item(parent, value, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
return self.type.render(node, value, None, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/types/complex.py", line 295, in render
element.render(node, element_value, child_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/indicators.py", line 251, in render
element.render(parent, element_value, child_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 232, in render
self._render_value_item(parent, value, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
return self.type.render(node, value, None, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/types/complex.py", line 295, in render
element.render(node, element_value, child_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/indicators.py", line 251, in render
element.render(parent, element_value, child_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 232, in render
self._render_value_item(parent, value, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
return self.type.render(node, value, None, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/types/complex.py", line 266, in render
attr_value = value[name] if name in value else NotSet
TypeError: argument of type 'float' is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/onvif/client.py", line 23, in wrapped
return func(*args, **kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/onvif/client.py", line 153, in wrapped
return call(params, callback)
File "/home/pi/.local/lib/python3.9/site-packages/onvif/client.py", line 143, in call
ret = func(params)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/proxy.py", line 46, in __call__
return self._proxy._binding.send(
File "/home/pi/.local/lib/python3.9/site-packages/zeep/wsdl/bindings/soap.py", line 123, in send
envelope, http_headers = self._create(
File "/home/pi/.local/lib/python3.9/site-packages/zeep/wsdl/bindings/soap.py", line 73, in _create
serialized = operation_obj.create(*args, **kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/wsdl/definitions.py", line 222, in create
return self.input.serialize(*args, **kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/wsdl/messages/soap.py", line 79, in serialize
self.body.render(body, body_value)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 232, in render
self._render_value_item(parent, value, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
return self.type.render(node, value, None, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/types/complex.py", line 295, in render
element.render(node, element_value, child_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/indicators.py", line 251, in render
element.render(parent, element_value, child_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 232, in render
self._render_value_item(parent, value, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
return self.type.render(node, value, None, render_path)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/types/simple.py", line 96, in render
node.text = self.xmlvalue(value)
File "/home/pi/.local/lib/python3.9/site-packages/zeep/xsd/types/builtins.py", line 27, in _wrapper
raise ValueError(
ValueError: The ReferenceToken type doesn't accept collections as value
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Script/onvif_test.py", line 35, in <module>
print(ptz.GotoPreset(request))
File "/home/pi/.local/lib/python3.9/site-packages/onvif/client.py", line 26, in wrapped
raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: The ReferenceToken type doesn't accept collections as value

这是执行预设命令的脚本(在不设置速度的情况下,这一命令非常有效(:

#!/usr/bin/python3
from functions import *

from onvif import ONVIFCamera
mycam = ONVIFCamera('xxx.xxx.xxx.xxx', 8080, 'admin', 'password', '/home/pi/.local/lib/python3.4/site-packages/wsdl/')
# Get Hostname
resp = mycam.devicemgmt.GetHostname()
print("My camera's hostname: " + str(resp.Name))
# Create media service object
media = mycam.create_media_service()
# Get target profile
media_profile = media.GetProfiles()[0]
#print(media_profile)
# Create ptz service object
ptz = mycam.create_ptz_service()
request = ptz.create_type('GotoPreset')
request.ProfileToken = media_profile.token
request.PresetToken = "Preset001"
request.Speed = 0.1
print("gotoPreset:")
print(request)
print(ptz.GotoPreset(request))

我使用下面的";ONVIF Python语言库";在RaspberryPi 4上。

  • 有人知道如何给我一些建议吗
  • 我哪里错了

感谢所有人!

我找到了解决方案。传递数据的正确方式是:

request.Speed = {'PanTilt': {'x': 0.1, 'y': 0.1}, 'Zoom': 0.1} # The camera seems to ignore the PanTilt and Zoom speeds I give it

即使不幸的是,我的ptz没有达到速度cge,我也告诉他去。。所以这东西没用(

无论如何,谢谢

最新更新