node-hikvision-api
node-hikvision-api copied to clipboard
Authentication Error
I am getting the following error when I tried to run the example code given in the github. Please find the details given below:
$ node ipnode.js
Connected to 192.168.20.244:80
Connection closed!
Connected to 192.168.20.244:80
EventNotificationAlert: {"html":{"head":[{"title":["Document Error: Unauthorized"]}],"body":[{"h2":["Access Error: 401 -- Unauthorized"],"p":["Authentication Error"]}]}}
events.js:174
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property 'eventType' of undefined
at /home/inapp/projects/nodecam/node_modules/node-hikvision-api/hikvision.js:49:48
at Parser.<anonymous> (/home/inapp/projects/nodecam/node_modules/xml2js/lib/parser.js:303:18)
at Parser.emit (events.js:189:13)
at SAXParser.onclosetag (/home/inapp/projects/nodecam/node_modules/xml2js/lib/parser.js:261:26)
at emit (/home/inapp/projects/nodecam/node_modules/sax/lib/sax.js:624:35)
at emitNode (/home/inapp/projects/nodecam/node_modules/sax/lib/sax.js:629:5)
at closeTag (/home/inapp/projects/nodecam/node_modules/sax/lib/sax.js:889:7)
at SAXParser.write (/home/inapp/projects/nodecam/node_modules/sax/lib/sax.js:1436:13)
at Parser.exports.Parser.Parser.parseString (/home/inapp/projects/nodecam/node_modules/xml2js/lib/parser.js:322:31)
at Parser.parseString (/home/inapp/projects/nodecam/node_modules/xml2js/lib/parser.js:5:59)
Emitted 'error' event at:
at Parser.exports.Parser.Parser.parseString (/home/inapp/projects/nodecam/node_modules/xml2js/lib/parser.js:326:16)
at Parser.parseString (/home/inapp/projects/nodecam/node_modules/xml2js/lib/parser.js:5:59)
at Socket.client.on (/home/inapp/projects/nodecam/node_modules/node-hikvision-api/hikvision.js:46:10)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
The code:
var ipcamera = require('node-hikvision-api');
// Options:
var options = {
host : '192.168.20.244',
port : '80',
user : 'admin',
pass : '1234qwer',
log : true,
};
var hikvision = new ipcamera.hikvision(options);
Please let me know what went wrong?
I'm getting the same error. Any ideas?
I was getting the same error. But after I realized that node-hikvision-api uses digest/basic authentication method. Then as you can see below, I changed the authentication method from digest to digest/basic.

If your error still persists you can use given below code for tracking alarms as I do. This code is taken from node-hikvision-api and I changed it slightly.
any patches? I have seen this api being used for node-red and it just crashes the entire service once this happens? Ideas how to fix it? my camera is set to digest/basic, onvif and cgi enabled
11 Jul 13:24:53 - [red] Uncaught Exception:
11 Jul 13:24:53 - TypeError: Cannot read property 'eventType' of undefined
at /home/pi/.node-red/node_modules/node-hikvision-api/hikvision.js:184:47
at Parser.<anonymous> (/home/pi/.node-red/node_modules/xml2js/lib/parser.js:303:18)
at emitOne (events.js:116:13)
at Parser.emit (events.js:211:7)
at SAXParser.onclosetag (/home/pi/.node-red/node_modules/xml2js/lib/parser.js:261:26)
at emit (/home/pi/.node-red/node_modules/sax/lib/sax.js:624:35)
at emitNode (/home/pi/.node-red/node_modules/sax/lib/sax.js:629:5)
at closeTag (/home/pi/.node-red/node_modules/sax/lib/sax.js:889:7)
at SAXParser.write (/home/pi/.node-red/node_modules/sax/lib/sax.js:1436:13)
at Parser.exports.Parser.Parser.parseString (/home/pi/.node-red/node_modules/xml2js/lib/parser.js:322:31)
at Parser.parseString (/home/pi/.node-red/node_modules/xml2js/lib/parser.js:5:59)
at handleData (/home/pi/.node-red/node_modules/node-hikvision-api/hikvision.js:182:9)
at Socket.<anonymous> (/home/pi/.node-red/node_modules/node-hikvision-api/hikvision.js:47:10)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
Iam getting same error on node i use node 12.13.0
node cam.js Connected to 46.252.x.x:81 events.js:187 throw er; // Unhandled 'error' event ^
ReferenceError: self is not defined
at /var/www/html/zoolandie/node_modules/node-hikvision-api/hikvision.js:70:6
at Parser.
Iam getting same error on node i use node 12.13.0
node cam.js Connected to 46.252.x.x:81 events.js:187 throw er; // Unhandled 'error' event ^
ReferenceError: self is not defined at /var/www/html/zoolandie/node_modules/node-hikvision-api/hikvision.js:70:6 at Parser. (/var/www/html/zoolandie/node_modules/xml2js/lib/parser.js:306:18) at Parser.emit (events.js:210:5) at SAXParser.onclosetag (/var/www/html/zoolandie/node_modules/xml2js/lib/parser.js:264:26) at emit (/var/www/html/zoolandie/node_modules/sax/lib/sax.js:624:35) at emitNode (/var/www/html/zoolandie/node_modules/sax/lib/sax.js:629:5) at closeTag (/var/www/html/zoolandie/node_modules/sax/lib/sax.js:889:7) at SAXParser.write (/var/www/html/zoolandie/node_modules/sax/lib/sax.js:1436:13) at Parser.exports.Parser.Parser.parseString (/var/www/html/zoolandie/node_modules/xml2js/lib/parser.js:325:31) at Parser.parseString (/var/www/html/zoolandie/node_modules/xml2js/lib/parser.js:5:59) Emitted 'error' event on Parser instance at: at Parser.exports.Parser.Parser.parseString (/var/www/html/zoolandie/node_modules/xml2js/lib/parser.js:329:16) at Parser.parseString (/var/www/html/zoolandie/node_modules/xml2js/lib/parser.js:5:59) at Socket. (/var/www/html/zoolandie/node_modules/node-hikvision-api/hikvision.js:46:10) at Socket.emit (events.js:210:5) at addChunk (_stream_readable.js:308:12) at readableAddChunk (_stream_readable.js:289:11) at Socket.Readable.push (_stream_readable.js:223:10) at TCP.onStreamRead (internal/stream_base_commons.js:182:23)
I get the same error, could you solve that problem?
Hello,
This issue was related to xml2js library as far as I remember. I did some adjustments to previously shared code but at this moment I could not remember. However, I can make a detailed explanation next week.