2012-04-03 4 views

ответ

7

С большим усилием, чем нужно, это ответ.

У меня есть версия пены 0.3.9. Мне пришлось подклассифицировать используемый класс транспорта и обернуть метод send для хранения последних принятых заголовков в классе транспорта.

import logging 
logging.basicConfig(level=logging.INFO) 
#logging.getLogger('suds.client').setLevel(logging.DEBUG) 
#logging.getLogger('suds.transport').setLevel(logging.DEBUG) 
#logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG) 
#logging.getLogger('suds.wsdl').setLevel(logging.DEBUG) 

from suds.client import Client 
from suds.xsd.doctor import ImportDoctor, Import 
from suds.transport.https import HttpAuthenticated 

class MyTransport(HttpAuthenticated): 
    def __init__(self,*args,**kwargs): 
     HttpAuthenticated.__init__(self, *args, **kwargs) 
     self.last_headers = None 

    def send(self,request): 
     result = HttpAuthenticated.send(self, request) 
     self.last_headers = result.headers 
     return result 

doctor = ImportDoctor(Import('http://schemas.xmlsoap.org/soap/encoding/')) 
svc_url = 'https://server/Service?wsdl' 
svc_user = 'username' 
svc_pass = 'password' 

client = Client(svc_url,doctor=doctor,transport=MyTransport()) 
# For some reason I can't be bothered to investigate, setting the username and password in 
# client kwargs doesn't pass them to the custom transport: 
client.set_options(location=svc_url.partition('?')[0],username=svc_user,password=svc_pass) 
# call a method 
client.service.SomeMethod() 
# look at headers 
client.options.transport.last_headers 
+0

Это выглядит хорошо, спасибо большое! Я рад, что это было не очевидно. – PriceChild

Смежные вопросы