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

Variable not written correctly in SOAP body #894

Closed
elsampsa opened this issue Dec 31, 2018 · 3 comments
Closed

Variable not written correctly in SOAP body #894

elsampsa opened this issue Dec 31, 2018 · 3 comments

Comments

@elsampsa
Copy link

elsampsa commented Dec 31, 2018

Hi,

I'm getting an erroneous value into the SOAP message body. The "Timeout" attribute should have value "PT1S", but instead, a mysterious string "P%P" appears.

<soap-env:Body>
    <ns0:PullMessages xmlns:ns0="http://www.onvif.org/ver10/events/wsdl">
        <ns0:Timeout>P%P</ns0:Timeout> <!-- Should have "PT1S" INSTEAD-->
        <ns0:MessageLimit>1</ns0:MessageLimit>
    </ns0:PullMessages>
</soap-env:Body>

I've confirmed this with zeep in verbose mode and with wireshark.

Zeep version: 3.2.0

Here is the script as per your debugging template:

from zeep.client import Client, CachingClient, Settings
from zeep.wsse.username import UsernameToken
import zeep.helpers

settings = Settings()
settings.strict = False
settings.xml_huge_tree = True

# # WSDL File
url = "https://www.onvif.org/ver10/events/wsdl/event.wsdl"
# # Point your browser here to get a sneak peak : https://www.onvif.org/ver10/events/wsdl/event.wsdl
# # Service : PullPointSubscription, Operation : PullMessages

# # *** The PullPointSubscription Service ***
print("creating a soap client with url = ", url)
client = CachingClient(wsdl=url, settings=settings)
print("soap client created")

ser = client.create_service("{http://www.onvif.org/ver10/events/wsdl}PullPointSubscriptionBinding","PullMessages") # the service is created OK
node = client.create_message(ser, "PullMessages", Timeout="PT1S", MessageLimit=1) 
# "==> ValueError: There is no default service defined. This is usually due to missing wsdl:service definitions in the WSDL"
# print(etree.tostring(node, pretty_print=True))

.. so it seems that your debugging template does not work if the the WSDL file does not have a default service.

Please do confirm this .. !

Here is also a more complex version. However for this one you need an IP camera:

from zeep.client import Client, CachingClient, Settings
from zeep.wsse.username import UsernameToken
import zeep.helpers

settings = Settings()
settings.strict = False
settings.xml_huge_tree = True

# # WSDL File
url = "https://www.onvif.org/ver10/events/wsdl/event.wsdl"
# # Point your browser here to get a sneak peak : https://www.onvif.org/ver10/events/wsdl/event.wsdl
# # Service : PullPointSubscription, Operation : PullMessages


import logging.config

# # Put Zeep into verbose mode
logging.config.dictConfig({
    'version': 1,
    'formatters': {
        'verbose': {
            'format': '%(name)s: %(message)s'
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'zeep.transports': {
            'level': 'DEBUG',
            'propagate': True,
            'handlers': ['console'],
        },
    }
})


# # You need a standard IP cam for this
ip="192.168.0.134"; user="admin"; passwd="123456"; port=80 # My home cam 1.  Now you know its username and password.  :)

xaddr = "http://"+ip+"/onvif/events_service"
print("creating a soap client with url = ", url)
zeep_client_pp = CachingClient(wsdl=url, wsse=UsernameToken(user, passwd, use_digest=True), settings=settings)
print("soap client created")
print("binding to service")
ws_client_pp = zeep_client_pp.create_service("{http://www.onvif.org/ver10/events/wsdl}PullPointSubscriptionBinding", xaddr)
print("service bound")

ws_client_pp.PullMessages(MessageLimit=1, Timeout="PT1S")
# Results in erroneous SOAP message body as described above

A related SO question : https://stackoverflow.com/questions/53989525/using-onvif-pullpoint-services-with-zeep

@elsampsa
Copy link
Author

elsampsa commented Mar 26, 2019

So, duration objects must be of the type isodate.Duration, otherwise Zeep silently produces garbage. This will make it work:

import isodate
Timeout = isodate.Duration(seconds=10)

Fair enough. But this could be in the documentation .. or maybe it is there already and its just me?

@uioporqwerty
Copy link

I did not know this as well or see it in the documentation. Thanks for your help @elsampsa. I spent quite some time wondering why the format would work fine in other platforms but not with zeep.

@TerehinAV
Copy link

TerehinAV commented Mar 17, 2020

Hi! I'm trying to get events using PullMessages method.

Here is a code:
https://gist.github.com/TerehinAV/0d5184bf9836b521e90474a2ff8d2cb9

zeep 3.4.0
onvif-zeep0.2.12

And I've got output with error 500 the parameter value is illegal. I googled this problem and used timestamp with isodate lib (timestamp is ok), but still have this problem.

What else can be a reason of this error?

creating a soap client with url =  https://www.onvif.org/ver10/events/wsdl/event.wsdl
soap client created
binding to service
service OK
creating a soap client with url =  https://www.onvif.org/ver10/events/wsdl/event.wsdl
soap client created
binding to service
service bound
zeep.transports: HTTP Post to http://YOUR_CAM_IP_NAME/onvif/events_service:
<?xml version='1.0' encoding='utf-8'?>
<soap-env:Envelope xmlns:soap-env="http://www.w3.org/2003/05/soap-envelope"><soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionRequest</wsa:Action><wsa:MessageID>urn:uuid:bd2dd500-48ff-485e-a548-178597630fab</wsa:MessageID><wsa:To>http://YOUR_CAM_IP_NAME/onvif/events_service</wsa:To><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>YOUR_USER_NAME</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">GM0OWCKp2oaBWHGAsUZo1sdW2pc=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">y85z/T/DiBKZo5bc1CIUsA==</wsse:Nonce><wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2020-03-17T09:01:27+00:00</wsu:Created></wsse:UsernameToken></wsse:Security></soap-env:Header><soap-env:Body><ns0:CreatePullPointSubscription xmlns:ns0="http://www.onvif.org/ver10/events/wsdl"/></soap-env:Body></soap-env:Envelope>
zeep.transports: HTTP Response from http://YOUR_CAM_IP_NAME/onvif/events_service (status: 200):
<?xml version="1.0" encoding="UTF-8"?>
<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:tnshik="http://www.hikvision.com/2011/event/topics" xmlns:hikwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl" xmlns:hikxsd="http://www.onvifext.com/onvif/ext/ver10/schema" xmlns:tas="http://www.onvif.org/ver10/advancedsecurity/wsdl"><env:Header><wsa:Action>http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionResponse</wsa:Action>
</env:Header>
<env:Body><tev:CreatePullPointSubscriptionResponse><tev:SubscriptionReference><wsa:Address>http://YOUR_CAM_IP_NAME/onvif/Events/PullSubManager_2020-03-17T09:01:25Z_7</wsa:Address>
</tev:SubscriptionReference>
<wsnt:CurrentTime>2020-03-17T09:01:25Z</wsnt:CurrentTime>
<wsnt:TerminationTime>2020-03-17T09:02:25Z</wsnt:TerminationTime>
</tev:CreatePullPointSubscriptionResponse>
</env:Body>
</env:Envelope>

zeep.transports: HTTP Post to http://YOUR_CAM_IP_NAME/onvif/events_service:
<?xml version='1.0' encoding='utf-8'?>
<soap-env:Envelope xmlns:soap-env="http://www.w3.org/2003/05/soap-envelope"><soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</wsa:Action><wsa:MessageID>urn:uuid:6f29e54c-342b-464a-942b-0a025ac419bf</wsa:MessageID><wsa:To>http://YOUR_CAM_IP_NAME/onvif/events_service</wsa:To><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>YOUR_USER_NAME</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">0EF6Mhkc7nM4NQAb4f7eykgAx1k=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">yHIud7hNMhQt9yGlN6MpTg==</wsse:Nonce><wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2020-03-17T09:01:27+00:00</wsu:Created></wsse:UsernameToken></wsse:Security></soap-env:Header><soap-env:Body><ns0:PullMessages xmlns:ns0="http://www.onvif.org/ver10/events/wsdl"><ns0:Timeout>PT1S</ns0:Timeout><ns0:MessageLimit>1</ns0:MessageLimit></ns0:PullMessages></soap-env:Body></soap-env:Envelope>
zeep.transports: HTTP Response from http://YOUR_CAM_IP_NAME/onvif/events_service (status: 500):
<?xml version="1.0" encoding="UTF-8"?>
<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:tnshik="http://www.hikvision.com/2011/event/topics" xmlns:hikwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl" xmlns:hikxsd="http://www.onvifext.com/onvif/ext/ver10/schema" xmlns:tas="http://www.onvif.org/ver10/advancedsecurity/wsdl"><env:Body><env:Fault><env:Code><env:Value>env:Sender</env:Value>
<env:Subcode><env:Value>ter:InvalidArgVal</env:Value>
<env:Subcode><env:Value>ter:InvalidParameter</env:Value>
</env:Subcode>
</env:Subcode>
</env:Code>
<env:Reason><env:Text xml:lang="en">the parameter value is illegal</env:Text>
</env:Reason>
</env:Fault>
</env:Body>
</env:Envelope>

None Traceback (most recent call last):
  File "/root/onvif_test/onvif_p3/__init__.py", line 92, in <module>
    print(ws_client_pp.PullMessages(MessageLimit=1, Timeout=timeout))
  File "/usr/local/lib/python3.6/site-packages/zeep/proxy.py", line 45, in __call__
    kwargs,
  File "/usr/local/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 130, in send
    return self.process_reply(client, operation_obj, response)
  File "/usr/local/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 195, in process_reply
    return self.process_error(doc, operation)
  File "/usr/local/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 362, in process_error
    subcodes=subcodes,
zeep.exceptions.Fault: the parameter value is illegal

Thanks in advance,
Andrey

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

3 participants