keshavdv / unifi-cam-proxy

Enable non-Ubiquiti cameras to work with Unifi NVR
MIT License
1.68k stars 235 forks source link

Invalid Token for Additional Cameras #73

Closed gitengstrom closed 3 years ago

gitengstrom commented 3 years ago

I have 5 cameras that I am attempting to add to my UDMP. 2 hikvision and 3 foscam. The two hikvision currently work fine, some tweaking will be needed to optimize in the future, both on the same token. But when I attempt to add another camera with that token I receive an error stating that the token is invalid and I need to generate a new one. But I can run either or both Hikvision cameras on that token without issue. I did generate a new token, but it did not work either. I feel like I am missing something very simple here.

Thanks in advance

Tom

keshavdv commented 3 years ago

Are you making sure you're using a new MAC address for each of them (change the --mac flag)?

gitengstrom commented 3 years ago

Yes, I do have the mac flag for each w/ a unique mac on each script. And I just tried again with a different mac and still no luck.

This is the output that I receive. I don't feel like there is any real info I am missing, but maybe you can see something I am not. `cameraproxy@unificameraproxy:~$ python ~/.local/bin/unifi-cam-proxy --host 10.0.100.1 --mac 'A4:BB:CC:00:23:40' -c client.pem -t JkxgAtMFqq4SW7FPooMQ7LYpFhsp92Ue rtsp -s rtsp://xxxx:xxxxxxxxxxx@10.0.50.14:554/videoMain

2021-08-28 18:43:49 unificameraproxy RTSPCam[93582] INFO Spawning stream for snapshots: ffmpeg -nostdin -y -re -rtsp_transport tcp -i "rtsp://xxxxxx:xxxxxxxxx@10.0.50.14:554/videoMain" -vf fps=1 -update 1 /tmp/tmpi5ro4ot4/screen.jpg

2021-08-28 18:43:49 unificameraproxy Core[93582] INFO Creating ws connection to wss://10.0.100.1:7442/camera/1.0/ws?token=JkxgAtMFqq4SW7FPooMQ7LYpFhsp92Ue

2021-08-28 18:43:49 unificameraproxy Core[93582] ERROR The token 'JkxgAtMFqq4SW7FPooMQ7LYpFhsp92Ue' is invalid. Please generate a new one and try again. Traceback (most recent call last): File "/home/cameraproxy/.local/bin/unifi-cam-proxy", line 8, in sys.exit(main()) File "/home/cameraproxy/.local/lib/python3.8/site-packages/unifi/main.py", line 109, in main loop.run_until_complete(c.run()) File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/home/cameraproxy/.local/lib/python3.8/site-packages/unifi/core.py", line 72, in run await connect() File "/home/cameraproxy/.local/lib/python3.8/site-packages/backoff/_async.py", line 66, in retry ret = await target(*args, **kwargs) File "/home/cameraproxy/.local/lib/python3.8/site-packages/unifi/core.py", line 43, in connect ws = await websockets.connect( File "/home/cameraproxy/.local/lib/python3.8/site-packages/websockets/legacy/client.py", line 629, in __await_impl__ await protocol.handshake( File "/home/cameraproxy/.local/lib/python3.8/site-packages/websockets/legacy/client.py", line 388, in handshake raise InvalidStatusCode(status_code) websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 403`

keshavdv commented 3 years ago

Can you try generating a few more new tokens and trying again?

gitengstrom commented 3 years ago

@keshavdv, the new code fixed it. Not sure why the previous code didn't work, but its working now. thank you.