FalkTannhaeuser / python-onvif-zeep

ONVIF Client Implementation in Python 2+3 (using https://github.com/mvantellingen/python-zeep instead of suds as SOAP client)
MIT License
420 stars 137 forks source link

Python ONVIF GotoPreset failed to set global movment Speed #89

Closed Kowa92 closed 1 year ago

Kowa92 commented 2 years ago

I'm trying to set the point called "Preset001" with a well-defined Speed but I can't as I get the following error on console:

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

This is the Script that executes the Preset command (without setting the speed, this one command works perfectly):

    #!/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))

I am using this ONVIF Python LIbrary on RaspberryPi 4.

Thanks to anyone!

tuandoan998 commented 1 year ago

Speed is a dict like: request.Speed = { "PanTilt": {"x": 0.0025, "y": 0.0025}, "Zoom": {"x": 0.0025} }

Kowa92 commented 1 year ago

Speed is a dict like: request.Speed = { "PanTilt": {"x": 0.0025, "y": 0.0025}, "Zoom": {"x": 0.0025} }

Ok thanks it works!

Although the PTZ does not seem to vary its speed of movement. I think that this last feature is not supported.. Could it be ??