Giúp sửa lỗi AttributeError: module ‘collections’ has no attribute ‘MutableMapping’

NameError: name ‘wikipedia’ is not defined
AttributeError: module ‘collections’ has no attribute ‘MutableMapping’

Code của bạn đâu rồi?

2 Likes
from requests import Response

from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.download_manager import WDMDownloadManager
from webdriver_manager.core.http import HttpClient
from webdriver_manager.core.logger import log
from youtube_search import YoutubeSearch
class CustomHttpClient(HttpClient):

    def get(self, url, params=None, **kwargs) -> Response:
        """
        Add you own logic here like session or proxy etc.
        """
        log("The call will be done with custom HTTP client")
        return requests.get(url, params, **kwargs)


def test_can_get_chrome_driver_with_custom_http_client():
    http_client = CustomHttpClient()
    download_manager = WDMDownloadManager(http_client)
    path = ChromeDriverManager(download_manager=download_manager).install()
    assert os.path.exists(path)



    results = YoutubeSearch('search terms', max_results=10).to_json()

    print(results)

    # returns a json string

    ########################################

    results = YoutubeSearch('search terms', max_results=10).to_dict()

    print(results)
    # returns a dictionary

lỗi

Traceback (most recent call last):
  File "C:\Users\HIEN\date.py", line 3, in <module>
    import requests
  File "C:\Users\HIEN\AppData\Local\Programs\Python\Python310\lib\site-packages\
requests\__init__.py", line 58, in <module>
    from . import utils
  File "C:\Users\HIEN\AppData\Local\Programs\Python\Python310\lib\site-packages\
requests\utils.py", line 30, in <module>
    from .cookies import RequestsCookieJar, cookiejar_from_dict
  File "C:\Users\HIEN\AppData\Local\Programs\Python\Python310\lib\site-packages\
requests\cookies.py", line 159, in <module>
    class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'

Bạn search thử tên lỗi trên Google là đã ra một vài kết quả hữu ích rồi.

Hoặc bạn sửa code của bạn hoặc nâng phiên bản của webdriver, requests,… để phù hợp với Python 3.10.

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?