Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Tampering Detection event not properly detected because of XML namespace problem #94

Open
b-ferd opened this issue May 3, 2024 · 0 comments

Comments

@b-ferd
Copy link

b-ferd commented May 3, 2024

When activating video tampering protection on the camera, the pyhik module reports an error when tampering is detected.

From my log:
hikvision.py:609: Error: Problem finding attribute: 'NoneType' object has no attribute 'text'

This is caused in function process_stream().
I traced it down a bit, and it is the first tree.find() call that fails, during the etype lookup right at the beginning in the try-except-block.

Motion detection works, the tree (dumped with ET.dump(tree)) looks like this in process_stream() (IP and MAC addresses redacted):
<ns0:EventNotificationAlert xmlns:ns0="http://www.std-cgi.com/ver20/XMLSchema" version="2.0"><ns0:ipAddress>XXX</ns0:ipAddress><ns0:ipv6Address>XXX</ns0:ipv6Address><ns0:portNo>80</ns0:portNo><ns0:protocol>HTTP</ns0:protocol><ns0:macAddress>XXX</ns0:macAddress><ns0:channelID>1</ns0:channelID><ns0:dateTime>2024-05-03T11:38:24+01:00</ns0:dateTime><ns0:activePostCount>1</ns0:activePostCount><ns0:eventType>VMD</ns0:eventType><ns0:eventState>active</ns0:eventState><ns0:eventDescription>Motion alarm</ns0:eventDescription><ns0:channelName>Camera 01</ns0:channelName></ns0:EventNotificationAlert>

But Tamper detection doesn't work, leads to error... tree looks like this:
<ns0:EventNotificationAlert xmlns:ns0="http://www.isapi.org/ver20/XMLSchema" version="2.0"><ns0:ipAddress>XXX</ns0:ipAddress><ns0:ipv6Address>XXX</ns0:ipv6Address><ns0:portNo>80</ns0:portNo><ns0:protocol>HTTP</ns0:protocol><ns0:macAddress>XXX</ns0:macAddress><ns0:channelID>1</ns0:channelID><ns0:dateTime>2024-05-03T11:38:28+01:00</ns0:dateTime><ns0:activePostCount>1</ns0:activePostCount><ns0:eventType>shelteralarm</ns0:eventType><ns0:eventState>active</ns0:eventState><ns0:eventDescription>shelteralarm</ns0:eventDescription><ns0:channelName>Camera 01</ns0:channelName></ns0:EventNotificationAlert>

In both cases, self.element_query('eventType', CONTEXT_ALERT) returns {http://www.std-cgi.com/ver20/XMLSchema}eventType as a namespace. So it within this namespace the code looks for entries. In the tamper protection event case, note that the namespace used by the camera is http://www.isapi.org/ver20/XMLSchema!

I've traced the problem down up to this point, but I'm not sure how to solve the core issue.
Is fetch_namespace() buggy? Or should the self.namespace entries be lists of namespaces rather than single namespace strings, and we should search all of them in case we don't find an entry in the first one we try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant