Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange build numbers 15.20.x.x unsupported #221

Closed
sumonick opened this issue Aug 30, 2017 · 10 comments
Closed

Exchange build numbers 15.20.x.x unsupported #221

sumonick opened this issue Aug 30, 2017 · 10 comments

Comments

@sumonick
Copy link

sumonick commented Aug 30, 2017

There seems to be a versioning error that is causing the code to crash.

Calling:

credentials = Credentials(username=emailUsername, password=emailPassword)
account = Account(primary_smtp_address=EmailAccount, credentials=credentials,
                          autodiscover=True)

response

<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="13" MinorBuildNumber="11" 

Error

Traceback (most recent call last):
  File "<ipython-input-21-4e8f156b43fb>", line 3, in <module>
    autodiscover=True)
  File "Lib\site-packages\exchangelib\account.py", line 54, in __init__
    credentials=credentials, verify_ssl=verify_ssl)
  File "Lib\site-packages\exchangelib\autodiscover.py", line 177, in discover
    protocol=protocol)
  File "Lib\site-packages\exchangelib\autodiscover.py", line 321, in _autodiscover_quick
    verify_ssl=protocol.verify_ssl)
  File "Lib\site-packages\exchangelib\protocol.py", line 168, in __call__
    protocol = super(CachingProtocol, cls).__call__(*args, **kwargs)
  File "Lib\site-packages\exchangelib\protocol.py", line 222, in __init__
    self.version = Version.guess(self)
  File "Lib\site-packages\exchangelib\version.py", line 194, in guess
    return cls._guess_version_from_service(protocol=protocol, hint=api_version)
  File "Lib\site-packages\exchangelib\version.py", line 224, in _guess_version_from_service
    ResolveNames(protocol=protocol).call(unresolved_entries=[protocol.credentials.username])
  File "Lib\site-packages\exchangelib\services.py", line 981, in call
    return_full_contact_data=return_full_contact_data,
  File "Lib\site-packages\exchangelib\services.py", line 72, in _get_elements
    response = self._get_response_xml(payload=payload)
  File "Lib\site-packages\exchangelib\services.py", line 159, in _get_response_xml
    new_version = Version.from_response(requested_api_version=api_version, response=r.text)
  File "Lib\site-packages\exchangelib\version.py", line 246, in from_response
    api_version_from_server = info.get('Version') or build.api_version()
  File "Lib\site-packages\exchangelib\version.py", line 102, in api_version
    return self.API_VERSION_MAP[self.major_version][self.minor_version]
KeyError: 20
@ecederstrand
Copy link
Owner

Do you know which Exchange version this is? According to https://technet.microsoft.com/en-gb/library/hh135098(v=exchg.150).aspx the latest build is at 15.1.x.x, so getting a build number of 15.20.x.x is somewhat surprising.

@sumonick
Copy link
Author

sumonick commented Aug 30, 2017

Using exchange 365
URL: https://outlook.office365.com/EWS/Exchange.asmx

Here is the full header from the response

<s:Header><h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="13" MinorBuildNumber="11" Version="V2017_07_11" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/></s:Header>

@ecederstrand
Copy link
Owner

Thanks. This looks like the first versions of an Exchange 2017 being rolled out. I'll see what I can come up with in the next days. You could try forcing the version to Exchange2016 as described in https://github.com/ecederstrand/exchangelib/blob/master/README.rst#setup-and-connecting but I'm not 100% sure it'll work.

@sumonick
Copy link
Author

sumonick commented Aug 30, 2017

Thanks for that, hopefully i'll hit the pain before everyone else does.
As a short term work around i have just added the minor 20 into my local version.py

15: {
            0: 'Exchange2013',  # Minor builds starting from 847 are Exchange2013_SP1, see api_version()
            1: 'Exchange2016',
            20: 'Exchange2016', 
}

It has not crashed as yet, so fingers cross.

@ecederstrand
Copy link
Owner

Ok, thanks! That's a very good data point.

@ecederstrand
Copy link
Owner

Google can't find any mention of an Exchange 2017 version coming up, and the build number returns not hits, either. Before I commit a fix, can you please test if this also works (canged "Exchange0216" to "Exchange2017")?

15: {
            0: 'Exchange2013',
            1: 'Exchange2016',
            20: 'Exchange2017', 
}

@ecederstrand ecederstrand changed the title KeyError 20 (API_VERSION_MAP) unable to connect to exchange server Exchange build numbers 15.20.x.x unsupported Aug 30, 2017
@sumonick
Copy link
Author

I tried changing it to "Exchange2017" and got the following:

Results
DEBUG:exchangelib.services:Trying API version Exchange2017 for account .....@......com.au
DEBUG:exchangelib.services:API version Exchange2017 was invalid for account .....@......com.au
DEBUG:exchangelib.protocol:Server outlook.office365.com: Waiting for session
....
DEBUG:exchangelib.services:Trying API version Exchange2016 for account .....@......com.au
DEBUG:exchangelib.services:New API version for account .....@......com.au (Exchange2017 -> Exchange2016)
INFO:exchangelib.version:API version "Exchange2016" worked but server reports version "V2017_07_11". Using "V2017_07_11"

I have therefore made the following changes and it seems to work for now...

Code
VERSIONS = {
'Exchange2007': ('Exchange2007', 'Microsoft Exchange Server 2007'),
'Exchange2007_SP1': ('Exchange2007_SP1', 'Microsoft Exchange Server 2007 SP1'),
'Exchange2007_SP2': ('Exchange2007_SP1', 'Microsoft Exchange Server 2007 SP2'),
'Exchange2007_SP3': ('Exchange2007_SP1', 'Microsoft Exchange Server 2007 SP3'),
'Exchange2010': ('Exchange2010', 'Microsoft Exchange Server 2010'),
'Exchange2010_SP1': ('Exchange2010_SP1', 'Microsoft Exchange Server 2010 SP1'),
'Exchange2010_SP2': ('Exchange2010_SP2', 'Microsoft Exchange Server 2010 SP2'),
'Exchange2010_SP3': ('Exchange2010_SP2', 'Microsoft Exchange Server 2010 SP3'),
'Exchange2013': ('Exchange2013', 'Microsoft Exchange Server 2013'),
'Exchange2013_SP1': ('Exchange2013_SP1', 'Microsoft Exchange Server 2013 SP1'),
'Exchange2015': ('Exchange2015', 'Microsoft Exchange Server 2015'),
'Exchange2015_SP1': ('Exchange2015_SP1', 'Microsoft Exchange Server 2015 SP1'),
'Exchange2016': ('Exchange2016', 'Microsoft Exchange Server 2016'),
'Exchange2017': ('V2017_07_11', 'Microsoft Exchange Server 2017'),
}
....
15: {
0: 'Exchange2013', # Minor builds starting from 847 are Exchange2013_SP1, see api_version()
1: 'Exchange2016',
20: 'Exchange2017', #Added
},
....
if api_version_from_server.startswith('V2_')
or api_version_from_server.startswith('V2015_')
or api_version_from_server.startswith('V2016_')
or api_version_from_server.startswith('V2017_'):

Results
DEBUG:exchangelib.protocol:Server outlook.office365.com: Releasing session 14741
DEBUG:exchangelib.services:Trying API version V2017_07_11 for account .....@......com.au
DEBUG:exchangelib.services:New API version for account .....@......com.au (Exchange2017 -> V2017_07_11)
DEBUG:exchangelib.folders:Root (root) created for None
DEBUG:exchangelib.account:Added account: .....@......com.au

@ecederstrand
Copy link
Owner

Thanks for the extra testing! I'll get the changes worked in and release a new version in the weekend.

@ecederstrand
Copy link
Owner

ecederstrand commented Aug 31, 2017

I just tested Exchange2017 as an API version, but it doesn't work. The server throws an error and we just silently fall back to Exchange2016, so I'll leave it here.

@Tyler-H
Copy link

Tyler-H commented Jan 7, 2019

Little bit late but if anyone comes across this while Googling, Exchange version 15.20 is Office Exchange 365 Online/Outlook.com. There was never an 'Exchange 2017'; they went from Exchange 2016 to Exchange 2019.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants