diff --git a/exchangelib/util.py b/exchangelib/util.py index ce5f96d..019b97f 100644 --- a/exchangelib/util.py +++ b/exchangelib/util.py @@ -186,6 +186,7 @@ def set_xml_value(elem, value, version): from .ewsdatetime import EWSDateTime, EWSDate from .fields import FieldPath, FieldOrder from .folders import EWSElement + from .version import Version if isinstance(value, string_types + (bool, bytes, int, Decimal, datetime.time, EWSDate, EWSDateTime)): elem.text = value_to_xml_text(value) elif isinstance(value, RestrictedElement): @@ -195,6 +196,8 @@ def set_xml_value(elem, value, version): if isinstance(v, (FieldPath, FieldOrder)): elem.append(v.to_xml()) elif isinstance(v, EWSElement): + if not isinstance(version, Version): + raise ValueError("'version' %r must be a Version instance" % version) elem.append(v.to_xml(version=version)) elif isinstance(v, RestrictedElement): elem.append(v) @@ -205,6 +208,8 @@ def set_xml_value(elem, value, version): elif isinstance(value, (FieldPath, FieldOrder)): elem.append(value.to_xml()) elif isinstance(value, EWSElement): + if not isinstance(version, Version): + raise ValueError("'version' %s must be a Version instance" % version) elem.append(value.to_xml(version=version)) else: raise ValueError('Unsupported type %s for value %s on elem %s' % (type(value), value, elem)) diff --git a/exchangelib/version.py b/exchangelib/version.py index 03d3f0f..56424a1 100644 --- a/exchangelib/version.py +++ b/exchangelib/version.py @@ -201,13 +201,12 @@ def guess(cls, protocol): @classmethod def _guess_version_from_service(cls, protocol, hint=None): # The protocol doesn't have a version yet, so add one with our hint, or default to latest supported version. - # Use ConvertId as a minimal request to the server to test if the version is correct. If not, ConvertId will - # try to guess the version automatically. Make sure the call to ConvertId does not require a version build. - from .properties import ENTRY_ID, EWS_ID, AlternateId - from .services import ConvertId + # Use ResolveNames as a minimal request to the server to test if the version is correct. If not, ResolveNames + # will try to guess the version automatically. + from .services import ResolveNames protocol.version = Version(build=None, api_version=hint or API_VERSIONS[-1]) try: - list(ConvertId(protocol=protocol).call([AlternateId(id="DUMMY", format=EWS_ID, mailbox="DUMMY")], ENTRY_ID)) + list(ResolveNames(protocol=protocol).call(unresolved_entries=[protocol.credentials.username])) except (ErrorInvalidSchemaVersionForMailboxVersion, ErrorInvalidServerVersion): raise TransportError('Unable to guess version') except ResponseMessageError: