quatanium / python-onvif

ONVIF Client Implementation in Python
MIT License
473 stars 321 forks source link

It's not clear how to set up a filter - TopicExpression for subscribe #53

Open Vorobeyko opened 7 years ago

Vorobeyko commented 7 years ago

I send request Subscribe, like this:

    subscribe.create_type('Subscribe')
    subscribe.Subscribe({'ConsumerReference': {'Address': "http://10.1.50.11:8000",},
                          'InitialTerminationTime': 'PT60S',
                          'Filter': 'o2kvmd:Telemetry//.'
                        })

But i got error:

Traceback (most recent call last): File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\onvif\client.py", line 169, in call ret = func(params) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\client.py", line 41, in call self._op_name, args, kwargs) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\wsdl\bindings\soap.py", line 110, in send options=options) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\wsdl\bindings\soap.py", line 68, in _create serialized = operation_obj.create(*args, *kwargs) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\wsdl\definitions.py", line 197, in create return self.input.serialize(args, kwargs) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\wsdl\messages\soap.py", line 64, in serialize self.body.render(body, body_value) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 191, in render self._render_value_item(parent, value, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 215, in _render_value_item return self.type.render(node, value, None, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\types\complex.py", line 253, in render element.render(parent, element_value, child_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\indicators.py", line 241, in render element.render(parent, element_value, child_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 191, in render self._render_value_item(parent, value, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 215, in _render_value_item return self.type.render(node, value, None, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\types\complex.py", line 253, in render element.render(parent, element_value, child_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\indicators.py", line 241, in render element.render(parent, element_value, child_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\any.py", line 117, in render self.validate(value, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\any.py", line 175, in validate self._validate_item(value, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\any.py", line 197, in _validate_item "See http://docs.python-zeep.org/en/master/datastructures.html" TypeError: Any element received object of type 'str', expected lxml.etree._Element or builtins.dict or zeep.xsd.valueobjects.AnyObject See http://docs.python-zeep.org/en/master/datastructures.html#any-objects for more information

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\onvif\client.py", line 25, in wrapped return func(*args, kwargs) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\onvif\client.py", line 182, in wrapped return call(params, callback) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\onvif\client.py", line 172, in call ret = func(params) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\client.py", line 41, in call self._op_name, args, kwargs) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\wsdl\bindings\soap.py", line 110, in send options=options) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\wsdl\bindings\soap.py", line 68, in _create serialized = operation_obj.create(*args, *kwargs) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\wsdl\definitions.py", line 197, in create return self.input.serialize(args, kwargs) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\wsdl\messages\soap.py", line 64, in serialize self.body.render(body, body_value) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 191, in render self._render_value_item(parent, value, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 215, in _render_value_item return self.type.render(node, value, None, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\types\complex.py", line 253, in render element.render(parent, element_value, child_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\indicators.py", line 241, in render element.render(parent, element_value, child_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 191, in render self._render_value_item(parent, value, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 215, in _render_value_item return self.type.render(node, value, None, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\types\complex.py", line 253, in render element.render(parent, element_value, child_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\indicators.py", line 241, in render element.render(parent, element_value, child_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 185, in render self.validate(value, render_path) File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\zeep\xsd\elements\element.py", line 236, in validate "Missing element %s" % (self.name), path=render_path) zeep.exceptions.ValidationError: Missing element Address (Subscribe.ConsumerReference)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py", line 1596, in globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py", line 974, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/avorobey/PycharmProjects/test_soapui/test_onvif.py", line 55, in test_suit.run() File "C:/Users/avorobey/PycharmProjects/test_soapui\library\TestSuitsImpl.py", line 45, in run current_test_case.run_test() File "C:/Users/avorobey/PycharmProjects/test_soapui\library\CTestCase.py", line 47, in run_test 'Filter': 'o2kvmd:Telemetry//.' File "C:\Users\avorobey\AppData\Local\Programs\Python\Python36-32\lib\site-packages\onvif\client.py", line 29, in wrapped raise ONVIFError(err) onvif.exceptions.ONVIFError: Unknown error: Missing element Address (Subscribe.ConsumerReference)

BUT, when i delete 'Filter': 'o2kvmd:Telemetry//.' this request work good. Question, how i can set Filter - TopicExression?

Vorobeyko commented 7 years ago

I found is a great solution:

    topic_expression_type = zeep_client.get_type('TopicExpressionType')
    from zeep import xsd
    topic_exp = xsd.Element('{http://docs.oasis-open.org/wsn/b-2}TopicExpression',xsd.ComplexType(topic_expression_type))
    subscribe = notification.create_type('Subscribe')
    any = xsd.AnyObject(topic_exp,topic_expression_type(_value_1=xsd.AnyObject(xsd.String(), 'o2kvmd:Telemetry//.'),Dialect='http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet'))
    obj = subscribe(ConsumerReference='http://10.1.50.11:8000', InitialTerminationTime='PT60S', Filter={'_value_1': any})
    notification.Subscribe(obj)
vinifr commented 6 years ago

What method did you use to create notification object or subscribe in your first post?