wechaty / python-wechaty

Python Wechaty is a Conversational RPA SDK for Chatbot Makers written in Python
https://wechaty.readthedocs.io/zh_CN/latest/
Apache License 2.0
1.55k stars 229 forks source link

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

Open Easen-L opened 6 months ago

Easen-L commented 6 months ago

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
kehuanjack commented 6 months ago

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

Easen-L commented 6 months ago

Understood, thank you

AurganicSubstance commented 5 months ago

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

suwjwj commented 5 months ago

为 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

yiwilee commented 1 month ago

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\wechatyinit.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?