1

Sorry for my english not being so well: Within a windows domain I try to connect to our exchangeserver (2010/SP3) using the example given on the pypi site:

from exchangelib import DELEGATE, NTLM, Account, Credentials, Configuration
import os, logging

logging.basicConfig(level=logging.DEBUG)

creds = Credentials(
    username='mydomain\\my.name', 
    password='mypassword')

config = Configuration(server='exchange.xxx.local/EWS/Exchange.asmx', credentials=creds)

account = Account(
    primary_smtp_address='my.name@mycompany.com',
    credentials=creds,
    autodiscover=False,
    access_type=DELEGATE)

for item in account.inbox.all().order_by('-datetime_received')[:30]:
    print(item.subject, item.body, item.attachments)

After starting the script, I get this output in the python console:

DEBUG:exchangelib.protocol:Waiting for _protocol_cache_lock
DEBUG:exchangelib.protocol:Protocol __call__ cache miss. Adding key '('https://exchange.xxx.local/EWS/Exchange.asmx', Credentials('mydomain\\my.name', '********'), True)'
DEBUG:exchangelib.transport:Getting service auth type for https://exchange.xxx.local/EWS/Exchange.asmx
DEBUG:exchangelib.transport:Requesting b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><s:Header><t:RequestServerVersion Version="Exchange2016" /></s:Header><s:Body><m:ResolveNames ReturnFullContactData="false"><m:UnresolvedEntry>mydomain\\my.name</m:UnresolvedEntry></m:ResolveNames></s:Body></s:Envelope>' from https://exchange.xxx.local/EWS/Exchange.asmx
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): exchange.xxx.local
Traceback (most recent call last):
  File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connectionpool.py", line 594, in urlopen
self._prepare_proxy(conn)
  File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connectionpool.py", line 810, in _prepare_proxy
conn.connect()
  File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connection.py", line 294, in connect
self._tunnel()
  File "C:\seProg\python353\Lib\http\client.py", line 832, in _tunnel
message.strip()))
OSError: Tunnel connection failed: 407 Proxy Access Denied    
... (and many more lines with error messages)

I also tried the other options from the exchangelib site with autodiscover=True and only creds= given (without config=). Without success. I then installed the EWS-Editor from https://ewseditor.codeplex.com/ in order to see, if connection via EWS may work at all in the environment of my company. It works fine with that tool, just have to give it my SMTP-address.

I would very much appreciate any help. Thanks in advance!

Chessyman
  • 11
  • 1
  • 4

1 Answers1

0

You probably need to tell exchangelib about your proxies. You can to this via environment variables: https://github.com/ecederstrand/exchangelib/issues/123#issuecomment-295648189 or via a custom HTTPAdapter class: https://github.com/ecederstrand/exchangelib/issues/156#issuecomment-312391095

Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
  • Thank you - I tried your first suggestion, but didn't work (second, I don't know how to build up the HTTPAdapter class). According to my exchange- and network-admins it is not a proxy-problem, because proxy use is not needed in internal (domain-) traffic: Exception for all addresses like: *.xxx.local. Our exchangeserver is "exchange.xxx.local". I tested this using the requests library with a simple `r = requests.get('http://exchange.xxx.local')` and it worked! So, no proxy use necessary - I would appreciate another hint! – Chessyman Jul 12 '17 at 08:48
  • The `requests.get('http://exchange.xxx.local')` test doesn't touch the TLS code path, which is where the error is occurring. Try with `requests.get('https://exchange.xxx.local/EWS/Exchange.asmx')` instead. Otherwise, you can try the troubleshooting section at https://github.com/ecederstrand/exchangelib#troubleshooting – Erik Cederstrand Jul 30 '17 at 12:07