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

Update discovery.py #1304

Closed
wants to merge 1 commit into from
Closed

Update discovery.py #1304

wants to merge 1 commit into from

Conversation

Gab-Z
Copy link

@Gab-Z Gab-Z commented Apr 29, 2024

Allow the initialization of the DNS_LOOKUP_ERROR variable to work without error.

In my use case importing:

from exchangelib import Folder

raised the exception :

File "/root/.pex/unzipped_pexes/0bf8be61a4ebad23d549d3f586c2e0a8702a896d/fast_api/routers/connecteurMail/__init__.py", line 10, in <module>
    from exchangelib import Folder
  File "/root/.pex/installed_wheels/9c88853ab554b6cb969a214da5615182d3ce47dc7bd99beb3dc0e805ab8af438/exchangelib-5.2.1-py3-none-any.whl/exchangelib/__init__.py", line 1, in <module>
    from .account import Account, Identity
  File "/root/.pex/installed_wheels/9c88853ab554b6cb969a214da5615182d3ce47dc7bd99beb3dc0e805ab8af438/exchangelib-5.2.1-py3-none-any.whl/exchangelib/account.py", line 6, in <module>
    from .autodiscover import Autodiscovery
  File "/root/.pex/installed_wheels/9c88853ab554b6cb969a214da5615182d3ce47dc7bd99beb3dc0e805ab8af438/exchangelib-5.2.1-py3-none-any.whl/exchangelib/autodiscover/__init__.py", line 2, in <module>
    from .discovery import Autodiscovery, discover
  File "/root/.pex/installed_wheels/9c88853ab554b6cb969a214da5615182d3ce47dc7bd99beb3dc0e805ab8af438/exchangelib-5.2.1-py3-none-any.whl/exchangelib/autodiscover/discovery.py", line 20, in <module>
    dns.resolver.LifetimeTimeout,
    ^^^^^^^^^^^^
AttributeError: module 'dns' has no attribute 'resolver'

Allow the initialization of the DNS_LOOKUP_ERROR variable to work without error.

In my use case importing:

```from exchangelib import Folder```

raised the exception :

```
File "/root/.pex/unzipped_pexes/0bf8be61a4ebad23d549d3f586c2e0a8702a896d/fast_api/routers/connecteurMail/__init__.py", line 10, in <module>
    from exchangelib import Folder
  File "/root/.pex/installed_wheels/9c88853ab554b6cb969a214da5615182d3ce47dc7bd99beb3dc0e805ab8af438/exchangelib-5.2.1-py3-none-any.whl/exchangelib/__init__.py", line 1, in <module>
    from .account import Account, Identity
  File "/root/.pex/installed_wheels/9c88853ab554b6cb969a214da5615182d3ce47dc7bd99beb3dc0e805ab8af438/exchangelib-5.2.1-py3-none-any.whl/exchangelib/account.py", line 6, in <module>
    from .autodiscover import Autodiscovery
  File "/root/.pex/installed_wheels/9c88853ab554b6cb969a214da5615182d3ce47dc7bd99beb3dc0e805ab8af438/exchangelib-5.2.1-py3-none-any.whl/exchangelib/autodiscover/__init__.py", line 2, in <module>
    from .discovery import Autodiscovery, discover
  File "/root/.pex/installed_wheels/9c88853ab554b6cb969a214da5615182d3ce47dc7bd99beb3dc0e805ab8af438/exchangelib-5.2.1-py3-none-any.whl/exchangelib/autodiscover/discovery.py", line 20, in <module>
    dns.resolver.LifetimeTimeout,
    ^^^^^^^^^^^^
AttributeError: module 'dns' has no attribute 'resolver'
```
@ecederstrand
Copy link
Owner

This doesn't make sense. If import dns.resolver doesn't work, then from dns.resolver import LifetimeTimeout shouldn't, either. There must be something else going on.

from exchangelib import Folder definitely works in a standard install from pip. It's tested by the test suite.

@Gab-Z
Copy link
Author

Gab-Z commented Apr 30, 2024

Hello, thanks for your reply and sorry for rushing in the subject without any cheering words. This library is great, it has worked like a charm in production for over a year now.

You are correct when saying taht something else is going on.
I couldn't reproduce the issue with a simple case.

The scenario is uvicorn starting a fastapi app which includes routers defined in modules. The from exchangelib import Folder statement is in one of those modules.

In my realworld case, it seems that importing Folder in the main module solved the issue.

I'll try to look further for the root cause if I can.

Thanks anyway for your time and gret work.

@ecederstrand
Copy link
Owner

Maybe you have a module somewhere in your own code called dns?

@Gab-Z
Copy link
Author

Gab-Z commented Apr 30, 2024

I think I found something. While searching for other mentions to the dns module name, i found that the pymongo package uses dnspython too here

Then adding from motor import motor_asyncio to my simple case test makes the exception mentioned above to reappear. (Note that motor is just the aynchronous version of pymongo)

Here is a minimalist reproducible example:

export DEMO_NAME="dns_resolver_exception_demo" &&\
mkdir $DEMO_NAME &&\
cd $DEMO_NAME &&\
python -m venv .venv &&\
source .venv/bin/activate &&\
pip install exchangelib &&\
pip install motor &&\
python -c "from motor import motor_asyncio;from exchangelib import Folder"

You should end up with :

  File "/home/glev/Documents/dns_resolver_exception_demo/.venv/lib/python3.12/site-packages/exchangelib/autodiscover/discovery.py", line 20, in <module>
    dns.resolver.LifetimeTimeout,
    ^^^^^^^^^^^^
AttributeError: module 'dns' has no attribute 'resolver'

Both solutions : changing the import syntax in discovery.py or importing exchangelib in the first level module seems to work.

I don't understand yet why things aren't working properly. pymongo's requirements says : dnspython>=1.16.0,<3.0.0

@ecederstrand
Copy link
Owner

Sounds like motor, or a motor dependency, monkey-patches the dns module. eventlet, for example, will annoyingly do that: eventlet/eventlet#805

Still, I don't think this is an issue with exchangelib, or an issue exchangelib should alleviate.

@ecederstrand
Copy link
Owner

I assume pip install motor dnspython and from motor import motor_asyncio;from dns import resolver would also fail. I suggest raising this issue with motor instead.

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

Successfully merging this pull request may close these issues.

None yet

2 participants