わかりました。私は最初に泡を使わなければなりませんでした。
import httplib
import urllib2 as u2
from suds.transport.http import HttpTransport
class HTTPSClientAuthHandler(u2.HTTPSHandler):
def __init__(self, key, cert):
u2.HTTPSHandler.__init__(self)
self.key = key
self.cert = cert
def https_open(self, req):
# Rather than pass in a reference to a connection class, we pass in
# a reference to a function which, for all intents and purposes,
# will behave as a constructor
return self.do_open(self.getConnection, req)
def getConnection(self, host, timeout=300):
return httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert)
class HTTPSClientCertTransport(HttpTransport):
def __init__(self, key, cert, *args, **kwargs):
HttpTransport.__init__(self, *args, **kwargs)
self.key = key
self.cert = cert
def u2open(self, u2request):
"""
Open a connection.
@param u2request: A urllib2 request.
@type u2request: urllib2.Request.
@return: The opened file-like urllib2 object.
@rtype: fp
"""
url = u2.build_opener(HTTPSClientAuthHandler(self.key, self.cert))
if self.u2ver() < 2.6:
return url.open(u2request)
else:
return url.open(u2request, timeout=self.options.timeout)
.
.
.
def consume_soap():
from suds.client import Client
from datetime import date
from calendar import monthrange
transport = HTTPSClientCertTransport('auth/key_no_passphrase.pem', 'auth/cert.pem')
client = Client(XLedgerInterface.WSDL_EXPORT_PATH, transport=transport)
year = date.today().year
month = date.today().month
first_date = str(date(year, month, 1))
last_date = str(date(year, month, monthrange(year, month)[1]))
xml = client.service.GetTimesheetEntriesData(sUserName=XLedgerInterface.USER_ID,
sKey=XLedgerInterface.KEY,
sApplication=XLedgerInterface.APPLICATION_NAME,
iEntityCode=XLedgerInterface.ENTITY_CODE,
dDateFrom=first_date,
dDateTo=last_date,
sFreeText='',
sFilter='',
eOption="Open")
return self._get_as_json(xml)