[Soap-Python] Can't get my request to work in pysimplesoap SoapClient

Mariano Reingart reingart at gmail.com
Tue Apr 28 16:43:28 CEST 2015


You can try the following:

XML = """
<v2:GetOrders xmlns:v2="%s">
  <v2:request>
    <v2:BusinessDate>2015-04-24T00:00:00</v2:BusinessDate>
  </v2:request>
</v2:GetOrders>
""" % namespaceValue
bd = SimpleXMLElement(XML)

response = client.call("GetOrders", bd)

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com

On Tue, Apr 28, 2015 at 10:42 AM, Tim Callaghan <tmcallaghan at gmail.com>
wrote:

> Ultimately, this is the Envelope I need to generate for my first
> integration. From there I'll be doing substantially more complicated ones
> (payload wise) with respect to the amount of XML I need to generate inside
> the Body.
>
> It's probably just a few well constructed lines of code, I can't figure
> them out.
>
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:v2="http://www.no-web-site.com/webservices/sales/v2" xmlns:sys="
> http://schemas.datacontract.org/2004/07/System">
>    <soapenv:Header/>
>    <soapenv:Body>
>       <v2:GetOrders>
>          <v2:request xmlns:v2="
> http://www.no-web-site.com/webservices/sales/v2">
>             <v2:BusinessDate>2015-04-24T00:00:00</v2:BusinessDate>
>          </v2:request>
>       </v2:GetOrders>
>    </soapenv:Body>
> </soapenv:Envelope>
>
>
> On Tue, Apr 28, 2015 at 8:21 AM, Tim Callaghan <tmcallaghan at gmail.com>
> wrote:
>
>> I guess my question is really about how I do anything interesting with
>> the call method. At the moment it doesn't seem obvious how I create any
>> non-trivial XML to pass into it, other than simple key/value pairs. I'm
>> calling an API where I need to pass complex XML with nested structures.
>>
>> If you can point me to an example I'd really appreciate it.
>>
>> -Tim
>>
>>
>> On Tue, Apr 28, 2015 at 7:50 AM, Tim Callaghan <tmcallaghan at gmail.com>
>> wrote:
>>
>>> I've already defined the v2 ns and namespace in my SoapClient()
>>> initialization, why would I want/need to define it again?
>>>
>>> client =
>>> SoapClient(location=soapLocation,action=soapAction,namespace=namespaceValue,ns=nsValue,trace=True,http_headers=httpHeaders)
>>>
>>> GetOrders gets the v2 ns applied to it automatically, is there a way to
>>> have that happen to all elements in SimpleXMLElement automatically?
>>>
>>> Thanks.
>>>
>>> -Tim
>>>
>>>
>>> On Mon, Apr 27, 2015 at 10:13 PM, Mariano Reingart <reingart at gmail.com>
>>> wrote:
>>>
>>>> You'll need to specify the namespace URI so the python parser can
>>>> detect it (in the same node or in the xml root):
>>>>
>>>> bd = SimpleXMLElement("""<v2:BusinessDate
>>>> xmlns:v2="%s">2015-04-24T00:00:00</v2:BusinessDate>""" % namespaceValue,
>>>>                       )
>>>>
>>>> Regards
>>>>
>>>> Mariano Reingart
>>>> http://www.sistemasagiles.com.ar
>>>> http://reingart.blogspot.com
>>>>
>>>> On Mon, Apr 27, 2015 at 9:48 PM, Tim Callaghan <tmcallaghan at gmail.com>
>>>> wrote:
>>>>
>>>>> That worked, so now I'm close.
>>>>>
>>>>> However, I need a little more for this,
>>>>> "<v2:request><v2:BusinessDate>2015-04-24T00:00:00</v2:BusinessDate></v2:request>".
>>>>> I can easily add the "request" tags, but if I ask for a "v2:" prefix it
>>>>> gives me parsing errors.
>>>>>
>>>>> I got the syntax from here,
>>>>> https://code.google.com/p/pysimplesoap/wiki/SoapClient#Basic_example_not_using_WSDL
>>>>>
>>>>> On Mon, Apr 27, 2015 at 6:22 PM, Mariano Reingart <reingart at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> On Mon, Apr 27, 2015 at 6:22 PM, Tim Callaghan <tmcallaghan at gmail.com
>>>>>> > wrote:
>>>>>>
>>>>>>> Here's my code. When I "print bd.as_xml()" it looks good to me, but
>>>>>>> all that ends up in my <v2:response> is 2015-04-24T00:00:00, not
>>>>>>> <BusinessDate>
>>>>>>> 2015-04-24T00:00:00</BusinessDate>. Help.  -Tim
>>>>>>>
>>>>>>>
>>>>>>> -------- BEGIN CODE --------------
>>>>>>>
>>>>>>> from pysimplesoap.client import SoapClient
>>>>>>> from pysimplesoap.simplexml import SimpleXMLElement
>>>>>>>
>>>>>>> soapLocation="https://www.changed-for-example.com/Sales2.svc
>>>>>>> <https://api5.brinkpos.net/Sales2.svc>"
>>>>>>> soapAction="
>>>>>>> http://www.changed-for-example.com/webservices/sales/v2/ISalesWebService2/
>>>>>>> <http://www.brinksoftware.com/webservices/sales/v2/ISalesWebService2/>
>>>>>>> "
>>>>>>> nsValue="v2"
>>>>>>> namespaceValue="
>>>>>>> http://www.changed-for-example.com/webservices/sales/v2
>>>>>>> <http://www.brinksoftware.com/webservices/sales/v2>"
>>>>>>> httpHeaders = {'AccessToken':'**NOT*THE*REAL*TOKEN',
>>>>>>> 'LocationToken':'**NOT*THE*REAL*TOKEN'}
>>>>>>>
>>>>>>> client =
>>>>>>> SoapClient(location=soapLocation,action=soapAction,namespace=namespaceValue,ns=nsValue,trace=True,http_headers=httpHeaders)
>>>>>>>
>>>>>>> bd =
>>>>>>> SimpleXMLElement("<BusinessDate>2015-04-24T00:00:00</BusinessDate>")
>>>>>>>
>>>>>>> response = client.GetOrders(request=bd)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> Can you test the following code instead calling client.getOrders
>>>>>> directly?
>>>>>>
>>>>>> response = client.call("GetOrders", bd)
>>>>>>
>>>>>> That will detect bd as a raw simple xml object to be serialized.
>>>>>> That generates the following output (with BusinessDate included):
>>>>>>
>>>>>> INFO:pysimplesoap.client:POST
>>>>>> https://www.changed-for-example.com/Sales2.svc
>>>>>> DEBUG:pysimplesoap.client:SOAPAction: "
>>>>>> http://www.changed-for-example.com/webservices/sales/v2/ISalesWebService2/GetOrders
>>>>>> "
>>>>>> Content-length: 296
>>>>>> Content-type: text/xml; charset="UTF-8"
>>>>>> AccessToken: **NOT*THE*REAL*TOKEN
>>>>>> LocationToken: **NOT*THE*REAL*TOKEN
>>>>>> DEBUG:pysimplesoap.client:<?xml version="1.0"
>>>>>> encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="
>>>>>> http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="
>>>>>> http://www.changed-for-example.com/webservices/sales/v2">
>>>>>> <soapenv:Header/>
>>>>>>
>>>>>> <soapenv:Body><BusinessDate>2015-04-24T00:00:00</BusinessDate></soapenv:Body></soapenv:Envelope>
>>>>>>
>>>>>> BTW, from where did you get the response=raw syntax?
>>>>>>
>>>>>> Best regards,
>>>>>>
>>>>>> Mariano Reingart
>>>>>> http://www.sistemasagiles.com.ar
>>>>>> http://reingart.blogspot.com
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/soap/attachments/20150428/e0ed032e/attachment-0001.html>


More information about the Soap mailing list