michaelborisov
michaelborisov

Reputation: 113

Get data from soap envelope zeep

I am trying to work with wsdl with the help of python library zeep. It works fine, but i can't find out how can I get data from request.

My code:

# encoding=utf-8
from requests.auth import HTTPBasicAuth  # or HTTPDigestAuth, or OAuth1, etc.
from zeep import Client
from zeep import helpers
from zeep.transports import Transport
import logging.config

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'],
        },
    }
})
wsdl = 'wsdl_url'
user = 'login'
password = 'password'
my_transport = Transport(http_auth=HTTPBasicAuth(user, password))
client = Client(
    wsdl, transport=my_transport
)
result = client.service.FunctionName(...)
print result

As a result, i get this:

{
 'schema': <Schema(location=None)>,
 '_value_1': <Element {urn:schemas-microsoft-com:xml-diffgram- v1}diffgram at 0x104ec0098>
}

Obviously, it is not what I want. Thanks to logging, I can see, that actually I get the needed information with envelope:

Each row has all inforamtion that I need

My question is, how can I access the data inside the envelope (I need rowOrders, which are partly displayed on screen)

Upvotes: 5

Views: 15547

Answers (2)

Cvetk0
Cvetk0

Reputation: 81

Using Zeep version 2.4.0 I was able to get the raw response by passing raw_response option to the client. This tells the client to return Requests response object.

Here's example code:

from zeep import Client

wsdl = 'wsdl_url'

client = Client(wsdl)

with client.options(raw_response=True):
    soap_result = client.service.function_name(...)

# Print out text from Requests response object returned    
print soap_result.text

Upvotes: 8

carloliwanag
carloliwanag

Reputation: 368

I also faced the same problem. So this is how I did it. This is not the best way to do it, but it can be a start and I wish the maker forgives me. Also, I am just starting to learn python.

clone the zeep project here: https://github.com/mvantellingen/python-zeep and go to that folder.

in transports.py, add this line in the constructor (_ init _):

self.response = ''

and then in the method post, before returning the response, add this line:

self.response = response

after this, build the package by executing

python setup.py install

this should be in your virtualenv (if you are using one)

so in your code, you can print

print my_transport.response.content

hope this helps

Upvotes: 4

Related Questions