HIRPA SILESHI
HIRPA SILESHI

Reputation: 5

Why am I getting AttributeError while trying to execute "import requests" from my Mac terminal?

I am trying to web-scrape using requests and Python 3.10 from my Mac. But I receive this error just from trying to import requests:

>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 30, in <module>
    from .cookies import RequestsCookieJar, cookiejar_from_dict
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 159, in <module>
    class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'

Do I need to downgrade my python version, or what could I do?

Upvotes: 0

Views: 154

Answers (1)

chris
chris

Reputation: 2063

The abstract base classes (abc's) in the collections module were moved to collections.abc in Python 3.3; in Python 3.10, the aliases were removed.

Your post doesn't make it clear what version of requests you're using or whether you require a new Python 3.10 feature, but hopefully one of the following options will work for you:

  • Create a Python 3.9 virtual environment and use the same version of requests, so those aliases are available.
  • See if requests has a newer version available that is compatible with Python 3.10. (Note many third-party libraries are not yet compatible.)

Upvotes: 2

Related Questions