X
X
xlamys2014-07-10 11:35:41
Python
xlamys, 2014-07-10 11:35:41

How is authentication done in soap headers, soap client (python + suds)?

Good afternoon, colleagues.
I ran into a problem when writing a soap client.
There is a ready-made version in php:

<?php
1. $client = new SoapClient('https://xx.xx.xx.xx/service/?wsdl');
2. $headers = array();
3. $headers[] = new SoapHeader('http://localhost/auth','Login','admin');
4. $headers[] = new SoapHeader('http://localhost/auth','Password','admin');
5. $client->__setSoapHeaders($headers);
6. $table_hi = $client->getTableByTitle('SomeTable');
7. $row_data = array(
8. 		array(
9.                          array(
10.                                  'name' => 'number',
11.                                 'value' => '55555555'
12.                          ),
13.                          array(
14.                                 'name' => 'data',
15.                                  'value' => '20140306185014'
16.                           ),
17. )
18. );
19. $rowset=$client->insertRowset($table_hi, $row_data);
20. ?>

I'm trying to rewrite this whole thing in python. (The key word here is "trying".)
I came across the Python suds library (if there are other relevant libraries, I will be glad for a tip).
By analogy with the client, I started rewriting in php.
from suds.client import Client
from suds.xsd.doctor import ImportDoctor, Import

imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
d = ImportDoctor(imp)
client = Client(url='https://xx.xx.xx.xx/service/?wsdl', doctor=d)
client.set_options(soapheaders=['http://localhost/auth','Login','admin'])
client.set_options(soapheaders=['http://localhost/auth','Password','admin'])
result = client.service.getTableByTitle('SomeTable')

In the php client, an array with authentication data is passed to the soap header, I could not find an example of how to implement this on suds, I tried it in different ways. suds.WebFault: Server raised fault: 'Wrong parameters for authorization'
I'm not strong in web services, if there is a link to an exhaustive source, please go to the studio.
Tell me where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gimntut, 2014-07-12
@gimntut

Perhaps like this:

import suds.client

try:
    auth_url = "https://url.to.my.service/authenticator?wsdl"
    auth_client = suds.client.Client(auth_url)
    cookie = auth_client.service.authenticate(user,password)
except Exception as e:
    print str(e)
    print auth_client.last_received()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question