Importing requests fails with no attribute mutablemapping
or ensure_text
¶
With Python 3.10.11 or requests 2.10.0, this error was coming up in Jupyter notebooks.
The problem¶
When you try to run import requests
, Jupyter notebook gives you one of the following errors:
- AttributeError: module 'collections' has no attribute 'MutableMapping'
- AttributeError: module 'six' has no attribute 'ensure_text'
The solution¶
While I don't know why this problem happens, I do know the solution! This problem takes two steps to fix.
First, we will upgrade the requests
and six
packages.
Second, if you're using Jupyter (or Jupyterlab or even VS Code notebooks), you'll need to restart your kernel.
In Jupyter, you would go to the Kernel menu up top, then click Restart. Test the fix by running import requests
again.