4

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)
Aura
  • 307
  • 2
  • 5
  • 11
  • 3
    Looks like the version of requests you are using is out of date. The [Mapping](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping) type was moved to `collections.abc`. – khelwood Mar 26 '22 at 22:39
  • I tried updating but it doesn't work what command do I use to update the module properly? – Aura Mar 26 '22 at 22:41
  • 2
    It's the `urllib3` version, not the `requests` version. – user2357112 Mar 26 '22 at 22:43

3 Answers3

5

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

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Aura
  • 307
  • 2
  • 5
  • 11
2

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

Gin
  • 51
  • 3
0

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)
eshirvana
  • 23,227
  • 3
  • 22
  • 38