cannot import name 'Mapping' from 'collections' on importing requests
Question:
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:ProgrammingWireUStest.py", line 1, in <module>
import requests
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesrequests__init__.py", line 43, in <module>
import urllib3
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3__init__.py", line 8, in <module>
from .connectionpool import (
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3connectionpool.py", line 29, in <module>
from .connection import (
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3connection.py", line 39, in <module>
from .util.ssl_ import (
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3util__init__.py", line 3, in <module>
from .connection import is_connection_dropped
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3utilconnection.py", line 3, in <module>
from .wait import wait_for_read
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3utilwait.py", line 1, in <module>
from .selectors import (
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3utilselectors.py", line 14, in <module>
from collections import namedtuple, Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:UsersJohnAppDataLocalProgramsPythonPython310libcollections__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)
Answers:
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)
As user2357112-supports-monica said, running pip install urllib3
fixes it.
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
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:ProgrammingWireUStest.py", line 1, in <module>
import requests
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesrequests__init__.py", line 43, in <module>
import urllib3
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3__init__.py", line 8, in <module>
from .connectionpool import (
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3connectionpool.py", line 29, in <module>
from .connection import (
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3connection.py", line 39, in <module>
from .util.ssl_ import (
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3util__init__.py", line 3, in <module>
from .connection import is_connection_dropped
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3utilconnection.py", line 3, in <module>
from .wait import wait_for_read
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3utilwait.py", line 1, in <module>
from .selectors import (
File "C:UsersJohnAppDataLocalProgramsPythonPython310libsite-packagesurllib3utilselectors.py", line 14, in <module>
from collections import namedtuple, Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:UsersJohnAppDataLocalProgramsPythonPython310libcollections__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)
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)
As user2357112-supports-monica said, running pip install urllib3
fixes it.
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