Aura
Aura

Reputation: 317

cannot import name 'Mapping' from 'collections' on importing requests

Python Version: Python 3.10.4
PIP Version: pip 22.0.4

So I was trying to make a small project with sockets, I added a feature to upload files but whenever I import requests, it throws this error. Below is the code I ran.

Traceback (most recent call last):
  File "C:\Programming\WireUS\test.py", line 1, in <module>
    import requests
  File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\__init__.py", line 43, in <module>
    import urllib3
  File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\__init__.py", line 8, in <module>
    from .connectionpool import (
  File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 29, in <module>
    from .connection import (
  File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 39, in <module>
    from .util.ssl_ import (
  File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\__init__.py", line 3, in <module>
    from .connection import is_connection_dropped
  File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 3, in <module>
    from .wait import wait_for_read
  File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\wait.py", line 1, in <module>
    from .selectors import (
  File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\selectors.py", line 14, in <module>
    from collections import namedtuple, Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:\Users\John\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py)

Even this basic code gives me that error.

import requests
import time

r = request.get("google.com").text
print(r)

time.sleep(999)

Upvotes: 4

Views: 29587

Answers (3)

Aura
Aura

Reputation: 317

As user2357112-supports-monica said, running pip install urllib3 fixes it.

Upvotes: 7

Gin
Gin

Reputation: 101

Just try to edit the selectors.py file

from

from collections import Mapping

to

from collections.abc import Mapping

This is a compatibility issue between different versions of python 3

Upvotes: 5

eshirvana
eshirvana

Reputation: 24568

you have to mention the schema (http, ftp,https) of your url :

import requests
import time

r = requests.get("https://google.com").text
print(r)

Upvotes: 0

Related Questions