def _get_shortname_from_docs(auth, types_url):
# Get the server version from types.xsd. We can't necessarily use the service auth type since it may not be the
# same as the auth type for docs.
log.debug('Getting %s with auth type %s', types_url, auth.__class__.__name__)
# Some servers send an empty response if we send 'Connection': 'close' header
from .protocol import BaseProtocol
with requests.sessions.Session() as s:
s.mount('http://', adapter=BaseProtocol.get_adapter())
s.mount('https://', adapter=BaseProtocol.get_adapter())
r = s.get(url=types_url, auth=auth, allow_redirects=False, stream=False)
log.debug('Request headers: %s', r.request.headers)
log.debug('Response code: %s', r.status_code)
log.debug('Response headers: %s', r.headers)
if r.status_code != 200:
raise TransportError('Unexpected HTTP status %s when getting %s (%s)' % (r.status_code, types_url, r.text))
if not is_xml(r.text):
raise TransportError('Unexpected result when getting %s. Maybe this is not an EWS server?%s' % (
types_url,
'\n\n%s[...]' % r.text[:200] if len(r.text) > 200 else '\n\n%s' % r.text if r.text else '',
))
return to_xml(r.text).get('version')
评论列表
文章目录