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)
As user2357112-supports-monica said, running pip install urllib3 fixes it.
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)
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
Related
This issue is coming right now. why i don't know. But i was not facing this issue before 2 / 3 days.
This error is coming, when my 'import request' starts running. I have tried every single solution on internet but nothing seems to worked.
"C:\Program Files\Python310\python.exe"
"E:/IT Vedant/Rough Work/1mg.py"
Traceback (most recent call last):
File "E:\IT Vedant\Rough Work\1mg.py", line 2, in <module>
import requests
File "C:\Program Files\Python310\lib\site-packages\requests\__init__.py", line 58, in <module>
from . import utils
File "C:\Program Files\Python310\lib\site-packages\requests\utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "C:\Program Files\Python310\lib\site-packages\requests\compat.py", line 7, in <module>
from .packages import chardet
File "C:\Program Files\Python310\lib\site-packages\requests\packages\__init__.py", line 3, in <module>
from . import urllib3
File "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3\__init__.py", line 10, in <module>
from .connectionpool import (
File "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3\response.py", line 5, in <module>
from ._collections import HTTPHeaderDict
File "C:\Program Files\Python310\lib\site-packages\requests\packages\urllib3\_collections.py", line 1, in <module>
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (C:\Program Files\Python310\lib\collections\__init__.py)
Process finished with exit code 1
You are using python 3.10
try changing from
from collections import Mapping
to from collections.abc import Mapping
My C:\Program Files\Python310\lib\collections\__init__.py from section didn't seem to have the required entries.
To resolve this, I added the following to that file:
from collections.abc import Mapping
from collections.abc import MutableMapping
from collections.abc import Sequence
Additionally my project .py file still had the legacy code line import collections which I replaced with the new code line from collections.abc import Mapping
in You python 3.10
go to this link
C:\Program Files\Python310\lib\collections\
and open ficher __init__.py
in this ficher change :
from collections import Mapping
to
from collections.abc import Mapping
I see this message after updating the robotframework version form 3.2.2 to 4.1.1
Maybe someone faced a similar issue and has a solution? I suppose it is somehow connected to another problem https://github.com/nokia/RED/issues/413
Here is Traceback:
File "kubeless.py", line 23, in <module>
from robot_hub import RobotHub
File "c:\opt\robot\robot_hub.py", line 9, in <module>
from rfhub import blueprints
File "C:\Python37\lib\site-packages\rfhub\blueprints\__init__.py", line 1, in <module>
from rfhub.blueprints.api import blueprint as api
File "C:\Python37\lib\site-packages\rfhub\blueprints\api\__init__.py", line 9, in <module>
from . import keywords
File "C:\Python37\lib\site-packages\rfhub\blueprints\api\keywords.py", line 7, in <module>
from robot.libdocpkg.htmlwriter import DocToHtml
ImportError: cannot import name 'DocToHtml' from 'robot.libdocpkg.htmlwriter' (C:\Python37\lib\site-packages\robot\libdocpkg\htmlwriter.py)
kubeless.py
...
from robot_hub import RobotHub
...
if __name__ == '__main__':
app.hub = RobotHub(app)
...
I found that package rfhub v 1.0.1 (https://pypi.org/project/robotframework-hub/) doesnt support robotframework version > 4.0. There isnt required method in htmlwriter.py
I am trying to make a discord bot, but I get the following weird error where it can not import asyncio.Transport, although I am able to use it normally outside this code.
The code:
import asyncio
import os
import discord
from dotenv import load_dotenv
The error message:
Traceback (most recent call last):
File "dis.py", line 1, in <module>
import asyncio
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\asyncio\__init__.py", line 21, in <module>
from .base_events import *
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", line 19, in <module>
import inspect
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\inspect.py", line 36, in <module>
import dis
File "C:\Users\A.Gawish\dis.py", line 3, in <module>
import discord
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\__init__.py", line 23, in <module>
from .client import Client
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 34, in <module>
import aiohttp
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\__init__.py", line 6, in <module>
from .client import (
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\client.py", line 32, in <module>
from . import hdrs, http, payload
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\http.py", line 7, in <module>
from .http_parser import (
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\http_parser.py", line 14, in <module>
from .base_protocol import BaseProtocol
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\base_protocol.py", line 4, in <module>
from .tcp_helpers import tcp_nodelay
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\tcp_helpers.py", line 20, in <module>
def tcp_keepalive(transport: asyncio.Transport) -> None:
AttributeError: module 'asyncio' has no attribute 'Transport'
Your filename was dis.py, which is used in another module. I resolved a similar issue by ensuring the filename is different from any other existing files in Lib
If you look at your error messages, it is indicating Python36. If Transport in asyncio was only released in Python37, you need to change the pathing in whatever program you're using to write the code in as it's looking at Python36.
Testing it as the command prompt would show that your system sees Python37 but your code doesn't. Fix the pathing and it should work then.
I am attempting to move over my web scraping program from using the requests library to the requests-html library to allow me to render the javascript on webpages. On the import of the module this error is thrown:
Traceback (most recent call last):
File "backend2.py", line 2, in <module>
import requests_html
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests_html.py", line 9, in <module>
import pyppeteer
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/__init__.py", line 30, in <module>
from pyppeteer.launcher import connect, launch, executablePath # noqa: E402
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/launcher.py", line 24, in <module>
from pyppeteer.browser import Browser
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/browser.py", line 15, in <module>
from pyppeteer.page import Page
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/page.py", line 20, in <module>
from pyppeteer.coverage import Coverage
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/coverage.py", line 15, in <module>
from pyppeteer.util import merge_dict
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/util.py", line 10, in <module>
from pyppeteer.chromium_downloader import check_chromium, chromium_executable
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/chromium_downloader.py", line 15, in <module>
from tqdm import tqdm
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tqdm/__init__.py", line 1, in <module>
from ._tqdm import tqdm
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tqdm/_tqdm.py", line 75, in <module>
mp_lock = mp.RLock() # multiprocessing lock
AttributeError: module 'multiprocessing' has no attribute 'RLock'
Any help is appreciated!
You are using Python 3.7, but the github of requests-html states that only Python 3.6 is supported (bottom of page). I get all kinds of horrible errors when I try to use Python 3.7 but 3.6 works fine. So, seems strange I know, but please try using 3.6
Even so, as #georgexsh states, there should still be a RLock available for import from multiprocessing in 3.7 so it looks like your error may actually be that one of your code files is called multiprocessing.py or you have your own package called multiprocessing (so you are importing that instead of the module you wanted).
I don't understand the error I get and searching online was not helpful.
Traceback (most recent call last):
File "/Users/<path>/file.py", line 1, in <module>
from coinmarketcap import Market
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/coinmarketcap/__init__.py", line 10, in <module>
from .core import Market
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/coinmarketcap/core.py", line 8, in <module>
import requests_cache
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests_cache/__init__.py", line 28, in <module>
from .core import(
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests_cache/core.py", line 14, in <module>
from requests import Session as OriginalSession
ImportError: cannot import name 'Session'
It seems to be generated from the very first line where the import and code is the following:
from coinmarketcap import Market
cmc = Market()
coins = cmc.ticker(limit=15) # assumes Dash in top 15.
print(coins)
Not sure if it helps but I had similar issue with import - turned out I have created requests.py file and imported stuff from there. It caused namespace clash as other libraries I used in the project were dependent on built-in requests module.