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
433 stars 144 forks source link

Bad Request for authenticated calls #34

Closed GeertvanHorrik closed 5 years ago

GeertvanHorrik commented 5 years ago

Hi,

I am investigating an issue of ONVIF camera support in HA (see https://github.com/home-assistant/home-assistant/issues/20668). It looks like calls that require authentication are not working.

For example, when I make a call to media_service.GetProfiles(), I get this error:

Couldn't setup camera 'cam1'. Error: Unknown error: (400, 'Bad Request')

Note that non-authenticated requests work fine:

[custom_components.camera.onvif] Setting up the ONVIF camera component
[custom_components.camera.onvif] Setting up the ONVIF camera device @ '192.168.1.xxx:80'
[custom_components.camera.onvif] Setting up the ONVIF device management service
[custom_components.camera.onvif] Retrieving current camera date/time
[custom_components.camera.onvif] Camera date/time: 2019-02-01 20:08:42
[custom_components.camera.onvif] System date/time: 2019-02-01 20:08:43.444658
[custom_components.camera.onvif] Retrieving capabilities
[custom_components.camera.onvif] Found 7 capabilities
[custom_components.camera.onvif] * Analytics
[custom_components.camera.onvif] * Device
[custom_components.camera.onvif] * Events
[custom_components.camera.onvif] * Imaging
[custom_components.camera.onvif] * Media
[custom_components.camera.onvif] * PTZ
[custom_components.camera.onvif] * Extension
[custom_components.camera.onvif] Setting up the ONVIF media service
[custom_components.camera.onvif] Setting up the ONVIF PTZ service
[custom_components.camera.onvif] Completed set up of the ONVIF camera component

Whenever I try to use the same username/password using a SOAP tool (for example, SoapUI), I am able to make the calls whenever I set authentication to Digest with the right username / password.

Maybe it's possible to get something from the headers (of a successful call):

POST http://192.168.1.xxx/onvif/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8
Content-Length: 216
Host: 192.168.1.xxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Digest username="admin", realm="Login to xxxx", nonce="xxxx", uri="/onvif/", response="xxxx", qop=auth, nc=00000001, cnonce="xxxx", opaque=""

Any ideas what could be the issue?

GeertvanHorrik commented 5 years ago

Never mind, I needed to update a few lines of code, works like a charm, thanks :)