python-wechaty icon indicating copy to clipboard operation
python-wechaty copied to clipboard

[Bug]: 运行示例,提示urllib3库中没有get_host,请问这要怎么解决?

Open Easen-L opened this issue 1 year ago • 5 comments

Environment

- wechaty:0.10.7
- wechaty-puppet: 0.4.23
- wechaty-puppet-service: 0.8.10
- wechaty-plugin-contrib: 0.0.25
- token type: padlocal|wxwork|xp
- the version of wechaty docker container: [0.65]

Description

"E:\A software\python\Python311\python.exe" "E:/Total Project/python project/order_automatic_push/python-wechaty-main/examples/contact-bot.py"
Traceback (most recent call last):
  File "E:\Total Project\python project\order_automatic_push\python-wechaty-main\examples\contact-bot.py", line 8, in <module>
    from wechaty import Wechaty, Contact
  File "E:\A software\python\Python311\Lib\site-packages\wechaty\__init__.py", line 54, in <module>
    from .wechaty import (
  File "E:\A software\python\Python311\Lib\site-packages\wechaty\wechaty.py", line 72, in <module>
    from wechaty.user.url_link import UrlLink
  File "E:\A software\python\Python311\Lib\site-packages\wechaty\user\__init__.py", line 8, in <module>
    from .message         import Message
  File "E:\A software\python\Python311\Lib\site-packages\wechaty\user\message.py", line 51, in <module>
    from .url_link import UrlLink
  File "E:\A software\python\Python311\Lib\site-packages\wechaty\user\url_link.py", line 10, in <module>
    from urllib3 import get_host
ImportError: cannot import name 'get_host' from 'urllib3' (E:\A software\python\Python311\Lib\site-packages\urllib3\__init__.py)

Minimum reproducible code

Snipaste_2023-12-15_14-19-03

Easen-L avatar Dec 15 '23 06:12 Easen-L

You can try to reduce its version to below 2.0. Use command like pip install "urllib3<2.0.0".

kehuanjack avatar Dec 17 '23 11:12 kehuanjack

Understood, thank you

Easen-L avatar Dec 19 '23 06:12 Easen-L

I tried lowering the version, got new problem: Traceback (most recent call last): File "D:\QWEN\main.py", line 31, in from wechaty import Wechaty File "D:\QWEN\venv\Lib\site-packages\wechaty_init_.py", line 54, in from .wechaty import ( File "D:\QWEN\venv\Lib\site-packages\wechaty\wechaty.py", line 111, in @dataclass ^^^^^^^^^ File "C:\Users\Writer's Cave\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 1220, in dataclass return wrap(cls) ^^^^^^^^^ File "C:\Users\Writer's Cave\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 1210, in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Writer's Cave\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 958, in _process_class cls_fields.append(_get_field(cls, name, type, kw_only)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Writer's Cave\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 815, in _get_field raise ValueError(f'mutable default {type(f.default)} for field ' ValueError: mutable default <class 'wechaty_puppet.schemas.puppet.PuppetOptions'> for field puppet_options is not allowed: use default_factory

AurganicSubstance avatar Jan 13 '24 07:01 AurganicSubstance

为 urllib3 添加 get_host 函数

from urllib.parse import urlparse def get_host(url: str) -> (str, str, str): parsed_url = urlparse(url) return parsed_url.scheme, parsed_url.netloc, parsed_url.path import urllib3 urllib3.get_host = get_host

suwjwj avatar Jan 21 '24 04:01 suwjwj

I tried lowering the version, got new problem: Traceback (most recent call last): File "D:\QWEN\main.py", line 31, in from wechaty import Wechaty File "D:\QWEN\venv\Lib\site-packages\wechaty__init__.py", line 54, in from .wechaty import ( File "D:\QWEN\venv\Lib\site-packages\wechaty\wechaty.py", line 111, in @DataClass ^^^^^^^^^ File "C:\Users\Writer's Cave\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 1220, in dataclass return wrap(cls) ^^^^^^^^^ File "C:\Users\Writer's Cave\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 1210, in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Writer's Cave\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 958, in _process_class cls_fields.append(_get_field(cls, name, type, kw_only)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Writer's Cave\AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 815, in _get_field raise ValueError(f'mutable default {type(f.default)} for field ' ValueError: mutable default <class 'wechaty_puppet.schemas.puppet.PuppetOptions'> for field puppet_options is not allowed: use default_factory

Can you fix it?

yiwilee avatar May 17 '24 18:05 yiwilee