在 Android 上的 kivymd 中使用 python 3.8 exchangelib 时出错

Posted

技术标签:

【中文标题】在 Android 上的 kivymd 中使用 python 3.8 exchangelib 时出错【英文标题】:Error using python 3.8 exchangelib in kivymd on Android 【发布时间】:2021-02-27 03:38:58 【问题描述】:

我使用 exchangelib 访问我的邮件,以从 python 中的 kivymd 交换。当我在计算机上运行我的代码时,它可以正常工作。但是,当我通过 android 上的 buildozer 部署它并在 Android 上启动我的应用程序时,我看到了解析器错误。请帮忙,我不明白问题的根源。

11-15 13:11:05.087 21267 22545 I python  :  Traceback (most recent call last):
11-15 13:11:05.087 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/cached_property.py", line 70, in __get__
11-15 13:11:05.089 21267 22545 I python  :  KeyError: 'resolver'
11-15 13:11:05.089 21267 22545 I python  :  
11-15 13:11:05.089 21267 22545 I python  :  During handling of the above exception, another exception occurred:
11-15 13:11:05.089 21267 22545 I python  :  
11-15 13:11:05.089 21267 22545 I python  :  Traceback (most recent call last):
11-15 13:11:05.090 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/dns/resolver.py", line 743, in read_resolv_conf
11-15 13:11:05.090 21267 22545 I python  :  FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf'
11-15 13:11:05.091 21267 22545 I python  :  
11-15 13:11:05.091 21267 22545 I python  :  During handling of the above exception, another exception occurred:
11-15 13:11:05.091 21267 22545 I python  :  
11-15 13:11:05.091 21267 22545 I python  :  Traceback (most recent call last):
11-15 13:11:05.092 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/app/main.py", line 155, in <module>
11-15 13:11:05.092 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/app/main.py", line 151, in main
11-15 13:11:05.093 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/kivy/app.py", line 854, in run
11-15 13:11:05.094 21267 22545 I python  :    File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
11-15 13:11:05.094 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/app/main.py", line 63, in on_start
11-15 13:11:05.095 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/app/main.py", line 108, in get_mail
11-15 13:11:05.095 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/exchangelib/account.py", line 116, in __init__
11-15 13:11:05.096 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/exchangelib/autodiscover/discovery.py", line 24, in discover
11-15 13:11:05.097 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/exchangelib/autodiscover/discovery.py", line 123, in discover
11-15 13:11:05.097 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/exchangelib/autodiscover/discovery.py", line 429, in _step_1
11-15 13:11:05.098 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/exchangelib/autodiscover/discovery.py", line 338, in _attempt_response
11-15 13:11:05.099 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/exchangelib/autodiscover/discovery.py", line 255, in _get_unauthenticated_response
11-15 13:11:05.099 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/exchangelib/autodiscover/discovery.py", line 379, in _is_valid_hostname
11-15 13:11:05.100 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/cached_property.py", line 74, in __get__
11-15 13:11:05.100 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/exchangelib/autodiscover/discovery.py", line 154, in resolver
11-15 13:11:05.101 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/dns/resolver.py", line 695, in __init__
11-15 13:11:05.101 21267 22545 I python  :    File "/home/andrey/PycharmProjects/stats_delay_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/stats_delay_android/dns/resolver.py", line 746, in read_resolv_conf
11-15 13:11:05.102 21267 22545 I python  :  dns.resolver.NoResolverConfiguration: None
11-15 13:11:05.102 21267 22545 I python  : Python for android ended.

【问题讨论】:

【参考方案1】:

exchangelib 需要进行 DNS 查找才能使自动发现工作。 NoResolverConfigurationdnspython 包中的一个例外,它告诉您它在您的系统中找不到有关要联系哪些名称服务器的任何信息。通常,这将位于/etc/resolv.conf,正如FileNotFoundError 错误所示。

我不知道 Android 上的 DNS 是如何工作的,也不知道 Python 如何访问 Android 上的 DNS 配置。如果您无法让 dnspython 获取配置,您可以在 Resolver.nameservers 属性中手动设置要使用的 DNS 服务器列表(例如 [8.8.8.8])。您可以通过 Autodiscovery.DNS_RESOLVER_ATTRS 属性在 exchangelib 中进行配置:

from exchangelib.auto discover import Autodiscovery

Autodiscovery.DNS_RESOLVER_ATTRS['nameservers'] = ['8.8.8.8']

【讨论】:

以上是关于在 Android 上的 kivymd 中使用 python 3.8 exchangelib 时出错的主要内容,如果未能解决你的问题,请参考以下文章

无法连接到 android KivyMD 上的 mysql 数据库

有没有办法在 Android 中测试 Kivymd 应用程序?

KivyMD 文件管理器功能

KivyMD,在 android 中看不到图标,但在 linux 上工作

Android Apk 仅适用于 KivyMd 崩溃

NLTK 不能在带有 KivyMD 的 Android Buildozer 应用程序中工作