2011-12-12 129 views
0

我試圖使用Python SOAP API的工作,但是我似乎無法讓我的頭設置正確。這是模式,任何想法如何在泡沫中完成這一點?Python的肥皂水憑據

<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://namespace.com"> 
    <xs:complexType name="Credentials"><xs:sequence/> 
    <xs:attribute name="username" type="xs:string" use="required"/> 
    <xs:attribute name="password" type="xs:string" use="required"/> 
    <xs:attribute name="customerID" type="xs:int"/> 
</xs:complexType> 
<xs:element name="credentials" nillable="true" type="Credentials"/></xs:schema> 

回答

1

好的,我明白了。看來你可以設置自定義XML節點所以在這裏我們去

import logging 
logging.basicConfig(level=logging.INFO) 
from suds.client import Client 
url = 'wsdl url' 
client = Client(url) 
logging.getLogger('suds.client').setLevel(logging.DEBUG) 
from suds.sax.element import Element 
#create an xml element at our namespace 
n = Element('credentials', ns=["cred","namespace.url"]) 
import suds.sax.attribute as attribute 
#the username, customerid and pass are atributes so we create them and append them to the node. 
un = attribute.Attribute("username","your username") 
up = attribute.Attribute("password","your password") 
cid = attribute.Attribute("customerID",1111) 
n.append(un).append(up).append(cid) 
client.set_options(soapheaders=n) 

〜CG

0

既然你創建你的WSDL定義的元素,你可以使用客戶端的工廠創建它的一個實例:

n = client.factory.create('credentials') 
n._username = "your username" 
n._password = "your password" 
n._customerID = 1111 

client.set_options(soapheaders=n) 

注意每個屬性名稱前的_。這將它們與具有相同名稱的類型中的非屬性區分開來。

-1

我想和大家分享我可以用我的憑據的聯繫方式,我希望它可以幫助您:

from suds.client import Client 
from suds.wsse import * 
import suds.bindings 

WSDL_URL = 'https://...?wsdl' 
URL = 'https://...' 
WSSE_USERNAME = 'wsse_username' 
WSSE_PASSWORD = 'wsse_password' 
USUARIO = 'my_user' 
PASSWORD = 'my_password' 

suds.bindings.binding.envns = ('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope') 
client = Client(WSDL_URL,cache=None) 
security = Security() 
token = UsernameToken(WSSE_USERNAME, WSSE_PASSWORD) 
security.tokens.append(token) 
client.set_options(wsse=security) 
client.set_options(location=URL) 
arrayMedicamentosDTO = [] 

medicamentosDTO = client.factory.create('medicamentosDTO') 
medicamentosDTO.f_evento = '14-03-2015' 
arrayMedicamentosDTO.append(medicamentosDTO) 

response = client.service.sendMedicamentos(arrayMedicamentosDTO, USUARIO, PASSWORD) 
0

您使用的這些泡沫的版本?

import logging 
logging.basicConfig(level=logging.INFO) 
from suds.client import Client 
url = 'wsdl url' 
client = Client(url) 
logging.getLogger('suds.client').setLevel(logging.DEBUG) 
from suds.sax.element import Element 
#create an xml element at our namespace 
n = Element('credentials', ns=["cred","namespace.url"]) 
import suds.sax.attribute as attribute 
#the username, customerid and pass are atributes so we create them and append them to the node. 
un = attribute.Attribute("username","your username") 
up = attribute.Attribute("password","your password") 
cid = attribute.Attribute("customerID",1111) 
n.append(un).append(up).append(cid) 
client.set_options(soapheaders=n)