5
我正在使用python泡沫模塊,並希望從泡沫響應中檢索響應頭(特別是Last-Modified)。如何從泡沫請求獲取響應頭
我正在使用python泡沫模塊,並希望從泡沫響應中檢索響應頭(特別是Last-Modified)。如何從泡沫請求獲取響應頭
比應該有必要的更多的努力是答案。
我在這裏有泡泡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
這看起來不錯,非常感謝!我很高興這並不明顯。 – PriceChild 2012-04-04 09:21:20