Учетные данные Python Suds - PullRequest
       20

Учетные данные Python Suds

0 голосов
/ 12 декабря 2011

Я пытаюсь работать с soap api в python, но не могу правильно настроить заголовки.Вот схема, есть идеи, как этого добиться в suds?

<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>

Ответы [ 4 ]

1 голос
/ 13 декабря 2011

Хорошо, у меня все работает. Кажется, вы можете установить пользовательские узлы 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 голосов
/ 10 мая 2017

какую версию пены вы используете?

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)
0 голосов
/ 15 марта 2015

Я просто хочу поделиться тем, как я мог соединиться со своими учетными данными, я надеюсь, что это поможет вам:

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 голосов
/ 24 декабря 2011

Поскольку элемент, который вы создаете, определен в вашем WSDL, вы можете создать его экземпляр, используя фабрику клиента:

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

client.set_options(soapheaders=n)

Обратите внимание на _ перед каждым именем атрибута. Это отличает их от неатрибутов в типе с тем же именем.

...