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

Fails to connect - Configuration() call #17

Closed
sleonov opened this issue Sep 7, 2016 · 14 comments
Closed

Fails to connect - Configuration() call #17

sleonov opened this issue Sep 7, 2016 · 14 comments

Comments

@sleonov
Copy link

sleonov commented Sep 7, 2016

Hi there,

I am trying to use the module to connect to my company Exchange
I am getting stuck at Configuration call which returns this errors - appears to fail to create SOAP call

My code:

!/usr/bin/env python3

import exchangelib as e

user='XXXXX'
password='YYYYYY'
service_endpoint='https://mail.micron.com'

config = e.Configuration(
service_endpoint=service_endpoint,
username=user,
password=password,
verify_ssl=True,
auth_type='NTLM',

)

Error message:

Traceback (most recent call last):
File "./e", line 14, in
auth_type='NTLM',
File "/usr/lib/python3.4/site-packages/exchangelib/configuration.py", line 47, in init
verify_ssl=verify_ssl,
File "/usr/lib/python3.4/site-packages/exchangelib/protocol.py", line 158, in call
protocol = super().call(_args, *_kwargs)
File "/usr/lib/python3.4/site-packages/exchangelib/protocol.py", line 191, in init
self.version = Version.guess(self)
File "/usr/lib/python3.4/site-packages/exchangelib/version.py", line 179, in guess
return cls._guess_version_from_service(protocol=protocol, hint=api_version)
File "/usr/lib/python3.4/site-packages/exchangelib/version.py", line 220, in _guess_version_from_service
return cls.get_version_from_service(protocol=protocol, api_version=api_version)
File "/usr/lib/python3.4/site-packages/exchangelib/version.py", line 235, in get_version_from_service
allow_redirects=False)
File "/usr/lib/python3.4/site-packages/exchangelib/util.py", line 353, in post_ratelimited
raise TransportError('Unknown failure\n' + log_msg % log_vals)
exchangelib.errors.TransportError: Unknown failure
Retry: 0
Waited: 0
Timeout: 120
Session: 14124
Thread: 139994368284416
Auth type: <requests_ntlm.requests_ntlm.HttpNtlmAuth object at 0x7f52ed03f550>
URL: https://mail.micron.com
Verify: True
Allow redirects: False
Response time: 0:00:00.487085
Status code: 301
Request headers: {'Accept-Encoding': 'compress, gzip', 'User-Agent': 'python-requests/2.11.1', 'Accept': '
/
', 'Connection': 'Keep-Alive', 'Content-Length': '448', 'Content-Type': 'text/xml; charset=utf-8'}
Response headers: {'X-Powered-By': 'ASP.NET', 'Pragma': 'no-cache', 'Connection': 'close', 'Location': 'https://mail.micron.com/owa/', 'Content-Length': '0', 'Cache-Control': 'no-cache', 'Server': 'Microsoft-IIS/8.5', 'Date': 'Wed, 07 Sep 2016 22:29:41 GMT'}
Request data: b'<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>DUMMY/m:UnresolvedEntry/m:ResolveNames/s:Body/s:Envelope'
Response data:

@ecederstrand
Copy link
Owner

Hi selonov,

Configuration takes either a service_endpoint or a server keyword argument. The former is the full URL to the EWS service endpoint, i.e. https://mail.example.com/EWS/Exchange.asmx. The latter is the server hostname, i.e. https://mail.example.com.

Just use the server argument unless your EWS service endpoint is located at a non-standard URL.

@sleonov
Copy link
Author

sleonov commented Sep 8, 2016

Thank you. That helped.

I am now stuck at parsing the Email item.

ids = account.inbox.find_items(shape=IdOnly)
items = account.inbox.get_items(ids)

for item in items:
subject = item.elem_for_field('subject')
body = item.elem_for_field('body')
date = item.elem_for_field('datetime_sent')
sender = item.elem_for_field('sender')
..

..

When I tyr to parse each element (sender for example), it only appears to
have Tag, but not the value.
I am not sure what I am doing wrong. Can you assist? Thank you!

On Wed, Sep 7, 2016 at 7:37 PM, Erik Cederstrand notifications@github.com
wrote:

Hi selonov,

Configuration takes either a service_endpoint or a server keyword
argument. The former is the full URL to the EWS service endpoint, i.e.
https://mail.example.com/EWS/Exchange.asmx. The latter is the server
hostname, i.e. https://mail.example.com.

Just use the server argument unless your EWS service endpoint is located
at a non-standard URL.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#17 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQkUdKx3xsLHmMv6za2Dow29jyeHndm2ks5qn1jbgaJpZM4J3bUc
.

@sleonov
Copy link
Author

sleonov commented Sep 8, 2016

sender_data = ET.tostring(sender)

On Thu, Sep 8, 2016 at 1:56 PM, Sergey Leonovich sleonovich@gmail.com
wrote:

Thank you. That helped.

I am now stuck at parsing the Email item.

ids = account.inbox.find_items(shape=IdOnly)
items = account.inbox.get_items(ids)

for item in items:
subject = item.elem_for_field('subject')
body = item.elem_for_field('body')
date = item.elem_for_field('datetime_sent')
sender = item.elem_for_field('sender')
..

..

When I tyr to parse each element (sender for example), it only appears to
have Tag, but not the value.
I am not sure what I am doing wrong. Can you assist? Thank you!

On Wed, Sep 7, 2016 at 7:37 PM, Erik Cederstrand <notifications@github.com

wrote:

Hi selonov,

Configuration takes either a service_endpoint or a server keyword
argument. The former is the full URL to the EWS service endpoint, i.e.
https://mail.example.com/EWS/Exchange.asmx. The latter is the server
hostname, i.e. https://mail.example.com.

Just use the server argument unless your EWS service endpoint is located
at a non-standard URL.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#17 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQkUdKx3xsLHmMv6za2Dow29jyeHndm2ks5qn1jbgaJpZM4J3bUc
.

@ecederstrand
Copy link
Owner

get_items() returns instances of the exchangelib.folders.Message model, not XML elements. So just do this:

ids = account.inbox.find_items(shape=IdOnly)
messages = account.inbox.get_items(ids)

for m in messages:
    print(m.subject, m.body, ...)

To fetch certain fields, e.g. datetime_sent, you need to set account.inbox.with_extra_fields=True before calling get_items().

@ecederstrand
Copy link
Owner

I just committed a fix so account.inbox.get_items(ids) will get the extra fields by default. account.inbox.with_extra_fields is now deprecated.

@sleonov
Copy link
Author

sleonov commented Sep 9, 2016

Thank you very much. I will give it a shot.

On Friday, September 9, 2016, Erik Cederstrand notifications@github.com
wrote:

get_items() returns instances of the exchangelib.folders.Message model,
not XML elements. So just do this:

ids = account.inbox.find_items(shape=IdOnly)
messages = account.inbox.get_items(ids)

for m in messages:
print(m.subject, m.body, ...)

To fetch certain fields, e.g. datetime_sent, you need to set
account.inbox.with_extra_fields=True before calling get_items().


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#17 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQkUdNVobb6VJBvKt5CJsUvwPeNcAgrFks5qoTfGgaJpZM4J3bUc
.

@sleonov
Copy link
Author

sleonov commented Sep 9, 2016

Will I be able to get new version from pip3 now ?

On Friday, September 9, 2016, Erik Cederstrand notifications@github.com
wrote:

I just committed a fix so account.inbox.get_items(ids) will get the extra
fields by default. account.inbox.with_extra_fields is now deprecated.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#17 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQkUdHYkjaiYfzOuwQz-PWSqgpAFyMQQks5qoUeWgaJpZM4J3bUc
.

@sleonov
Copy link
Author

sleonov commented Sep 9, 2016

Also. Perhaps one suggestion. If I supply invalid Windows credentials in
configuration call - I get timeout error after very very long time. Is
there a timeout parameter? If not perhaps it should be added so I don't sit
waiting for very long. I plan to use this script it automated process so I
want to know fast if my credetials are wrong.

Thanks again.

On Friday, September 9, 2016, Erik Cederstrand notifications@github.com
wrote:

I just committed a fix so account.inbox.get_items(ids) will get the extra
fields by default. account.inbox.with_extra_fields is now deprecated.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#17 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQkUdHYkjaiYfzOuwQz-PWSqgpAFyMQQks5qoUeWgaJpZM4J3bUc
.

@sleonov
Copy link
Author

sleonov commented Sep 9, 2016

Trying to upgrade to newer version on F23:

[root@sergey_vm1 bin]# pip3 install exchangelib --upgrade
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting exchangelib
Using cached exchangelib-1.6.2.tar.gz
Requirement already up-to-date: requests>=2.7 in
/usr/lib/python3.4/site-packages (from exchangelib)
Requirement already up-to-date: requests-ntlm>=0.2.0 in
/usr/lib/python3.4/site-packages (from exchangelib)
Requirement already up-to-date: dnspython3>=1.12.0 in
/usr/lib/python3.4/site-packages (from exchangelib)
Requirement already up-to-date: pytz in /usr/lib/python3.4/site-packages
(from exchangelib)
Collecting lxml (from exchangelib)
Using cached lxml-3.6.4.tar.gz
Requirement already up-to-date: python-ntlm3 in
/usr/lib/python3.4/site-packages (from requests-ntlm>=0.2.0->exchangelib)
Collecting six (from python-ntlm3->requests-ntlm>=0.2.0->exchangelib)
Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: lxml, exchangelib, six
Found existing installation: lxml 3.4.4
Uninstalling lxml-3.4.4:
Successfully uninstalled lxml-3.4.4
Running setup.py install for lxml
Complete output from command /usr/bin/python3 -c "import setuptools,
tokenize;file='/tmp/pip-build-1ltrlsab/lxml/setup.py';exec(compile(getattr(tokenize,
'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))"
install --record /tmp/pip-894lisxe-record/install-record.txt
--single-version-externally-managed --compile:
Building lxml version 3.6.4.
Building without Cython.
ERROR: b'/bin/sh: xslt-config: command not found\n'
** make sure the development packages of libxml2 and libxslt are
installed **

Using build configuration of libxslt
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.4
creating build/lib.linux-x86_64-3.4/lxml
copying src/lxml/doctestcompare.py -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/__init__.py -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/_elementpath.py -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/sax.py -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/ElementInclude.py -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/usedoctest.py -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/pyclasslookup.py -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/cssselect.py -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/builder.py -> build/lib.linux-x86_64-3.4/lxml
creating build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/__init__.py ->

build/lib.linux-x86_64-3.4/lxml/includes
creating build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/diff.py -> build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/defs.py -> build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/init.py ->
build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/ElementSoup.py ->
build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/soupparser.py ->
build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/_setmixin.py ->
build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/usedoctest.py ->
build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/formfill.py ->
build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/clean.py -> build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/_diffcommand.py ->
build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/html5parser.py ->
build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/builder.py -> build/lib.linux-x86_64-3.4/lxml/html
copying src/lxml/html/_html5builder.py ->
build/lib.linux-x86_64-3.4/lxml/html
creating build/lib.linux-x86_64-3.4/lxml/isoschematron
copying src/lxml/isoschematron/init.py ->
build/lib.linux-x86_64-3.4/lxml/isoschematron
copying src/lxml/lxml.etree.h -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/lxml.etree_api.h -> build/lib.linux-x86_64-3.4/lxml
copying src/lxml/includes/xinclude.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/uri.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/xmlschema.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/htmlparser.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/xslt.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/tree.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/xmlparser.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/xpath.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/schematron.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/config.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/dtdvalid.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/c14n.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/etreepublic.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/xmlerror.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/relaxng.pxd ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/etree_defs.h ->
build/lib.linux-x86_64-3.4/lxml/includes
copying src/lxml/includes/lxml-version.h ->
build/lib.linux-x86_64-3.4/lxml/includes
creating build/lib.linux-x86_64-3.4/lxml/isoschematron/resources
creating build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/rng
copying src/lxml/isoschematron/resources/rng/iso-schematron.rng ->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/rng
creating build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl
copying src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl ->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl
copying src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl ->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl
creating
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying
src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl
->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying
src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl
->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying
src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl
->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying
src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl
->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying
src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl
->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying
src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt ->
build/lib.linux-x86_64-3.4/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
running build_ext
building 'lxml.etree' extension
creating build/temp.linux-x86_64-3.4
creating build/temp.linux-x86_64-3.4/src
creating build/temp.linux-x86_64-3.4/src/lxml
gcc -pthread -Wno-unused-result -DDYNAMIC_ANNOTATIONS_ENABLED=1
-DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector-strong --param=ssp-buffer-size=4
-grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64
-mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Isrc/lxml/includes
-I/usr/include/python3.4m -c src/lxml/lxml.etree.c -o
build/temp.linux-x86_64-3.4/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:83:20: fatal error: Python.h: No such file or
directory
compilation terminated.
Compile failed: command 'gcc' failed with exit status 1
creating tmp
cc -I/usr/include/libxml2 -c /tmp/xmlXPathInit1gv1hfr4.c -o
tmp/xmlXPathInit1gv1hfr4.o
/tmp/xmlXPathInit1gv1hfr4.c:2:1: warning: return type defaults to ‘int’
[-Wimplicit-int]
main (int argc, char **argv) {
^
cc tmp/xmlXPathInit1gv1hfr4.o -lxml2 -o a.out
error: command 'gcc' failed with exit status 1

----------------------------------------

Rolling back uninstall of lxml
Command "/usr/bin/python3 -c "import setuptools,
tokenize;file='/tmp/pip-build-1ltrlsab/lxml/setup.py';exec(compile(getattr(tokenize,
'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))"
install --record /tmp/pip-894lisxe-record/install-record.txt
--single-version-externally-managed --compile" failed with error code 1 in
/tmp/pip-build-1ltrlsab/lxml
[root@sergey_vm1 bin]#

On Fri, Sep 9, 2016 at 8:07 AM, Sergey Leonovich sleonovich@gmail.com
wrote:

Will I be able to get new version from pip3 now ?

On Friday, September 9, 2016, Erik Cederstrand notifications@github.com
wrote:

I just committed a fix so account.inbox.get_items(ids) will get the
extra fields by default. account.inbox.with_extra_fields is now
deprecated.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#17 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQkUdHYkjaiYfzOuwQz-PWSqgpAFyMQQks5qoUeWgaJpZM4J3bUc
.

@ecederstrand
Copy link
Owner

Yes, version 1.6.2 is available on PyPI now.

The timeout is intentional (see #16). In short, there's no way to distinguish between an account that has been rate-limited, and and invalid credentials. But since this is popping up again, I think there should be a solution for this. Maybe something like Credentials(..., fail_fast=True)?

@ecederstrand
Copy link
Owner

ecederstrand commented Sep 9, 2016

Re: the build error: that's pip install lxml failing. You'll have to work out how to fix that on Fedora or ultimately with the lxml folks. Usually it's caused by some XML devel package missing on your system.

@sleonov
Copy link
Author

sleonov commented Sep 10, 2016

Erik. I appreciate all your help. I got it to work as I needed. I ended
implementing external timeout handler so I will terminate my program that
attempts to access exchange account if no response is received in 60
seconds. I do think having that parameter you are mentioning is good idea.
User most likely will not want to wait for 20 minutes waiting on timeout
error. Especially in cases like mine when I need response fast. I use this
in automated flow to search mails for process exceptions.

Have a good one.

On Friday, September 9, 2016, Erik Cederstrand notifications@github.com
wrote:

Yes, version 1.6.2 is available on PyPI now.

The timeout is intentional (see #16
#16). In short,
there's no way to distinguish between an account that has been
rate-limited, and and invalid credentials. But since this is popping up
again, I think there should be a solution for this. Maybe something like Credentials(...,
fail_fast=True)?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#17 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQkUdPmR0f9k63hCmZKqtR-5HtlHpNngks5qoWjJgaJpZM4J3bUc
.

@ecederstrand
Copy link
Owner

It's on the TODO now to add such a feature. Thanks for your suggestions!

@sleonov
Copy link
Author

sleonov commented Sep 13, 2016

Thanks

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

2 participants