Closed doublewinter0 closed 11 months ago
@wj-Mcat Review 一下
运行 BOT 时遇到同样的报错:
Traceback (most recent call last):
File "/data/Projects/wechaty-pratice/main.py", line 21, in <module>
from wechaty import (
File "/data/Projects/wechaty-pratice/venv/lib/python3.10/site-packages/wechaty/__init__.py", line 54, in <module>
from .wechaty import (
File "/data/Projects/wechaty-pratice/venv/lib/python3.10/site-packages/wechaty/wechaty.py", line 72, in <module>
from wechaty.user.url_link import UrlLink
File "/data/Projects/wechaty-pratice/venv/lib/python3.10/site-packages/wechaty/user/__init__.py", line 8, in <module>
from .message import Message
File "/data/Projects/wechaty-pratice/venv/lib/python3.10/site-packages/wechaty/user/message.py", line 51, in <module>
from .url_link import UrlLink
File "/data/Projects/wechaty-pratice/venv/lib/python3.10/site-packages/wechaty/user/url_link.py", line 10, in <module>
from urllib3 import get_host
ImportError: cannot import name 'get_host' from 'urllib3' (/data/Projects/wechaty-pratice/venv/lib/python3.10/site-packages/urllib3/__init__.py)
目前我的解决方案是重新安装 2.0.0
版本以下的 urllib3 库(并加入 requirements.txt
):
pip install -U 'urllib3<2'
上述问题的原因是 urllib3 在 2.0.0 版本中移除了部分弃用的 API(相关变更:https://github.com/urllib3/urllib3/compare/1.26.16...2.0.0a1#diff-793e73e680de400394dedf7d080fbcef6e74c065ffcc10b8c3dc11217a786e0bL38 ),其中就包括目前 wechaty/user/url_link.py
所使用的 get_host
(相关 PR:https://github.com/urllib3/urllib3/pull/2139 )
LGTM
@gsfish thanks for your suggestion, I have added the package dependency rule in https://github.com/wechaty/python-wechaty/commit/5892250b6d0b40119d510ae17619c7fbaf8623a4
pip3 install wechaty 最新版 还是0.10.7 并没有更新到0.10.8版本
In user.url_link.py, we use urllib3.util.url.get_host method, which is deprecated.
So I use the recommended method urllib3.util.url.parse_url instead. As a matter of fact, the deprecated method is removed in newer version.
There seems to be a small problem with the code, as follows:
The method's declared return type does not appear to match the actual return type.