mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.87k stars 578 forks source link

zeep.exceptions.Fault: The action requested requires authorization and the sender is not authorized -> profile = media.GetProfiles()[0] #1381

Open fti-sbargule opened 1 year ago

fti-sbargule commented 1 year ago

code file

from zeep import Client
from zeep.wsse.username import UsernameToken

ptz_wsdl = "/home/suyog/stitcher/PTZcamera_image/PTZcamera_control/python-onvif-zeep/wsdl/ptz.wsdl"
media_wsdl = "/home/suyog/stitcher/PTZcamera_image/PTZcamera_control/python-onvif-zeep/wsdl/media.wsdl"

ip = ""
port = ""
username = ""
password = ""

xaddr = "http://"+ip+":"+port+"/onvif/ptz_service"

media_client = Client(wsdl=media_wsdl, wsse=UsernameToken(
    username, password, use_digest=True))
media = media_client.create_service(
    "{http://www.onvif.org/ver10/media/wsdl}MediaBinding", xaddr)

ptz_client = Client(wsdl=ptz_wsdl, wsse=UsernameToken(
    username, password, use_digest=True))
ptz = ptz_client.create_service(
    "{http://www.onvif.org/ver20/ptz/wsdl}PTZBinding", xaddr)
print("ptz")
print(media.__dir__())
profile = media.GetProfiles()[0]
print("profile")
ptz_config = ptz.GetConfigurationOptions(profile.PTZConfiguration.token)

velocity = {
    "PanTilt": {
        "x": ptz_config.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Min,
        "y": ptz_config.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Min,
    },
}

ptz.ContinuousMove(profile.token, Velocity=velocity)

REQUEST SEND to PTZ camera:-

OPTION:-:http://192.168.10.35:80/onvif/ptz_service
ENVELOPE:-:<Element {http://www.w3.org/2003/05/soap-envelope}Envelope at 0x7f9613422d00>
HTTP HEADERS :-: {'SOAPAction': '"http://www.onvif.org/ver10/media/wsdl/GetProfiles"', 
                          'Content-Type': 'application/soap+xml; charset=utf-8; 
                          action="http://www.onvif.org/ver10/media/wsdl/GetProfiles"'}

Response from camera :-

RESPONSE COD :-: <Response [400]>
RESPONSE     :-:   b'<?xml version="1.0" encoding="UTF-8"?>\r\n<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tst="http://www.onvif.org/ver10/storage/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:dn="http://www.onvif.org/ver10/network/wsdl" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl" xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12" xmlns:http="http://schemas.xmlsoap.org/wsdl/http" xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsadis="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2" xmlns:wsrf-rw="http://docs.oasis-open.org/wsrf/rw-2" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:tnsn="http://www.eventextension.com/2011/event/topics" xmlns:extwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl" xmlns:extxsd="http://www.onvifext.com/onvif/ext/ver10/schema" xmlns:tas="http://www.onvif.org/ver10/advancedsecurity/wsdl" xmlns:tr2="http://www.onvif.org/ver20/media/wsdl" xmlns:axt="http://www.onvif.org/ver20/analytics"><env:Body><env:Fault><env:Code><env:Value>env:Sender</env:Value>\r\n<env:Subcode><env:Value>ter:NotAuthorized</env:Value>\r\n</env:Subcode>\r\n</env:Code>\r\n<env:Reason><env:Text xml:lang="en">The action requested requires authorization and the sender is not authorized</env:Text>\r\n</env:Reason>\r\n</env:Fault>\r\n</env:Body>\r\n</env:Envelope>\r\n'

Error :-

Traceback (most recent call last):
  File "/home/suyog/zeep_demo.py", line 25, in <module>
    profile = media.GetProfiles()[0]
  File "/home/suyog/zeep_onvif/lib/python3.10/site-packages/zeep/proxy.py", line 46, in __call__
    return self._proxy._binding.send(
  File "/home/suyog/zeep_onvif/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 138, in send
    return self.process_reply(client, operation_obj, response)
  File "/home/suyog/zeep_onvif/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 232, in process_reply
    return self.process_error(doc, operation)
  File "/home/suyog/zeep_onvif/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 394, in process_error
    raise Fault(
zeep.exceptions.Fault: The action requested requires authorization and the sender is not authorized