def guess(cls, protocol):
"""
Tries to ask the server which version it has. We haven't set up an Account object yet, so we generate requests
by hand. We only need a response header containing a ServerVersionInfo element.
The types.xsd document contains a 'shortname' value that we can use as a key for VERSIONS to get the API version
that we need in SOAP headers to generate valid requests. Unfortunately, the Exchagne server may be misconfigured
to either block access to types.xsd or serve up a wrong version of the document. Therefore, we only use
'shortname' as a hint, but trust the SOAP version returned in response headers.
To get API version and build numbers from the server, we need to send a valid SOAP request. We can't do that
without a valid API version. To solve this chicken-and-egg problem, we try all possible API versions that this
package supports, until we get a valid response. If we managed to get a 'shortname' previously, we try the
corresponding API version first.
"""
log.debug('Asking server for version info')
# We can't use a session object from the protocol pool for docs because sessions are created with service auth.
auth = get_auth_instance(credentials=protocol.credentials, auth_type=protocol.docs_auth_type)
try:
shortname = cls._get_shortname_from_docs(auth=auth, types_url=protocol.types_url)
log.debug('Shortname according to %s: %s', protocol.types_url, shortname)
except (TransportError, ParseError) as e:
log.info(text_type(e))
shortname = None
api_version = VERSIONS[shortname][0] if shortname else None
return cls._guess_version_from_service(protocol=protocol, hint=api_version)
评论列表
文章目录