import nonebot 时 tzlocal/win32.py/get_localzone_name 报错
synodriver opened this issue · 13 comments
描述问题:
启动时报错
如何复现?
仅仅是import nonebot
就会报错
神奇的是,在将sched.py里面修改后
if AsyncIOScheduler:
scheduler = AsyncIOScheduler(timezone="Asia/Shanghai")
就解决了现在正在这样苟着用
期望的结果
可以正常运行
环境信息:
- OS: [win10]
- Python Version: [3.8.5]
- Nonebot Version: [2.0.0a6]
截图
import nonebot
Traceback (most recent call last):
File "E:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-473157fb80ba>", line 1, in <module>
import nonebot
File "E:\pycharm\PyCharm 2020.1.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "E:\Anaconda3\lib\site-packages\nonebot\__init__.py", line 135, in <module>
from nonebot.sched import scheduler
File "E:\pycharm\PyCharm 2020.1.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "E:\Anaconda3\lib\site-packages\nonebot\sched.py", line 19, in <module>
scheduler = AsyncIOScheduler()
File "E:\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 87, in __init__
self.configure(gconfig, **options)
File "E:\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 126, in configure
self._configure(config)
File "E:\Anaconda3\lib\site-packages\apscheduler\schedulers\asyncio.py", line 48, in _configure
super(AsyncIOScheduler, self)._configure(config)
File "E:\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 697, in _configure
self.timezone = astimezone(config.pop('timezone', None)) or get_localzone()
File "E:\Anaconda3\lib\site-packages\tzlocal\win32.py", line 93, in get_localzone
_cache_tz = pytz.timezone(get_localzone_name())
File "E:\Anaconda3\lib\site-packages\tzlocal\win32.py", line 84, in get_localzone_name
raise pytz.UnknownTimeZoneError('Can not find timezone ' + tzkeyname)
pytz.exceptions.UnknownTimeZoneError: 'Can not find timezone '
提供一下环境中 pytz
和 tzlocal
的版本(执行 pip list
)。
pytz 2020.1
pytzdata 2020.1
tzlocal 2.1
测试没有报错
pip list|findstr "pytz"
pytz 2020.4
pip list|findstr "tzlocal"
tzlocal 2.1
pytzdata 无(没有这个包)
一样的错误
首先确认你的 python 环境。
接下来在正确的 python 环境中:
贴一下 pip list
结果中的 pytz
pytzdata
tzlocal
apscheduler
的版本
和在 python shell 中执行下面这段代码的结果的截图:
>>> from tzlocal import get_localzone
>>> get_localzone()
>>> from apscheduler.schedulers.asyncio import AsyncIOScheduler
>>> AsyncIOScheduler()
>>> from tzlocal import get_localzone
>>> get_localzone()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\Anaconda3\lib\site-packages\tzlocal\win32.py", line 93, in get_localzone
_cache_tz = pytz.timezone(get_localzone_name())
File "E:\Anaconda3\lib\site-packages\tzlocal\win32.py", line 84, in get_localzone_name
raise pytz.UnknownTimeZoneError('Can not find timezone ' + tzkeyname)
pytz.exceptions.UnknownTimeZoneError: 'Can not find timezone '
>>> from apscheduler.schedulers.asyncio import AsyncIOScheduler
>>> AsyncIOScheduler()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 87, in __init__
self.configure(gconfig, **options)
File "E:\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 126, in configure
self._configure(config)
File "E:\Anaconda3\lib\site-packages\apscheduler\schedulers\asyncio.py", line 48, in _configure
super(AsyncIOScheduler, self)._configure(config)
File "E:\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 697, in _configure
self.timezone = astimezone(config.pop('timezone', None)) or get_localzone()
File "E:\Anaconda3\lib\site-packages\tzlocal\win32.py", line 93, in get_localzone
_cache_tz = pytz.timezone(get_localzone_name())
File "E:\Anaconda3\lib\site-packages\tzlocal\win32.py", line 84, in get_localzone_name
raise pytz.UnknownTimeZoneError('Can not find timezone ' + tzkeyname)
pytz.exceptions.UnknownTimeZoneError: 'Can not find timezone '
>>>
以上是输出
贴一下 pip list 结果中的 pytz pytzdata tzlocal apscheduler 的版本
贴一下 pip list 结果中的 pytz pytzdata tzlocal apscheduler 的版本
APScheduler 3.6.3
pytz 2020.4
pytzdata 2020.1
tzlocal 2.1
跟我的版本都一模一样,我执行却都可以...
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from tzlocal import get_localzone
>>> get_localzone()
<DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>
>>> from apscheduler.schedulers.asyncio import AsyncIOScheduler
>>> AsyncIOScheduler()
<apscheduler.schedulers.asyncio.AsyncIOScheduler object at 0x0000020F8913BF40>
无法复现..
无法复现 +1
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from tzlocal import get_localzone >>> get_localzone() <DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD> >>> from apscheduler.schedulers.asyncio import AsyncIOScheduler >>> AsyncIOScheduler() <apscheduler.schedulers.asyncio.AsyncIOScheduler object at 0x0000020F8913BF40>
https://github.com/regebro/tzlocal/blob/2.1/tzlocal/win32.py#L84
看了一下你的报错,看起来跟这个 2.1 版本的 get_localzone_name
的实现有关,是上游问题。
相关issue:
regebro/tzlocal#103
建议重设一下本机时区,估计就好了
https://github.com/regebro/tzlocal/blob/2.1/tzlocal/win32.py#L84
看了一下你的报错,看起来跟这个 2.1 版本的
get_localzone_name
的实现有关,是上游问题。相关issue:
regebro/tzlocal#103建议重设一下本机时区,估计就好了
感谢,确实正常了,需要在控制面板设置时区