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 user.url_link #399

Merged
merged 5 commits into from
Jul 15, 2023
Merged

Update user.url_link #399

merged 5 commits into from
Jul 15, 2023

Conversation

doublewinter0
Copy link
Contributor

@doublewinter0 doublewinter0 commented May 15, 2023

In user.url_link.py, we use urllib3.util.url.get_host method, which is deprecated.

def get_host(url):
    """
    Deprecated. Use :func:`parse_url` instead.
    """
    p = parse_url(url)
    return p.scheme or "http", p.hostname, p.port

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:

@staticmethod
def can_parser(url: str) -> bool:
    """the source of url

    Args:
        url (str): github urllink

    Returns:
        bool: whether is github based url
    """
    return parse_url(url).hostname

The method's declared return type does not appear to match the actual return type.

Signed-off-by: doublewinter0 <erdong.me@gmail.com>
Signed-off-by: doublewinter0 <erdong.me@gmail.com>
@doublewinter0
Copy link
Contributor Author

@wj-Mcat Review 一下

@gsfish
Copy link

gsfish commented Jul 15, 2023

运行 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(相关变更:urllib3/urllib3@1.26.16...2.0.0a1#diff-793e73e680de400394dedf7d080fbcef6e74c065ffcc10b8c3dc11217a786e0bL38 ),其中就包括目前 wechaty/user/url_link.py 所使用的 get_host(相关 PR:urllib3/urllib3#2139

@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Jul 15, 2023

LGTM

@wj-Mcat wj-Mcat merged commit af5515d into wechaty:main Jul 15, 2023
4 checks passed
wj-Mcat added a commit that referenced this pull request Jul 15, 2023
wj-Mcat added a commit that referenced this pull request Jul 15, 2023
@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Jul 15, 2023

@gsfish thanks for your suggestion, I have added the package dependency rule in 5892250

@liyancai
Copy link

pip3 install wechaty 最新版 还是0.10.7 并没有更新到0.10.8版本

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

4 participants