首页 前端知识 ImportError: cannot import name ‘JSONDecodeError‘ from ‘requests.exceptions‘

ImportError: cannot import name ‘JSONDecodeError‘ from ‘requests.exceptions‘

2024-10-17 11:10:23 前端知识 前端哥 491 36 我要收藏

所遇问题

(base) C:\Users\M>conda info -e
Traceback (most recent call last):
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\exception_handler.py", line 17, in __call__
    return func(*args, **kwargs)
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\cli\main.py", line 51, in main_subshell
    from .conda_argparse import do_call, generate_parser, generate_pre_parser
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\cli\conda_argparse.py", line 50, in <module>
    from .main_create import configure_parser as configure_parser_create
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\cli\main_create.py", line 11, in <module>
    from ..notices import notices
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\notices\__init__.py", line 3, in <module>
    from .core import notices  # noqa: F401
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\notices\core.py", line 14, in <module>
    from . import cache, fetch, views
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\notices\cache.py", line 25, in <module>
    from ..utils import ensure_dir_exists
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\utils.py", line 23, in <module>
    from .gateways.disk.read import compute_sum
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\gateways\disk\read.py", line 31, in <module>
    from ...exceptions import CondaUpgradeError, CondaVerificationError, PathNotFoundError
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\exceptions.py", line 16, in <module>
    from requests.exceptions import JSONDecodeError
ImportError: cannot import name 'JSONDecodeError' from 'requests.exceptions' (D:\Anaconda3_2022.10\lib\site-packages\requests\exceptions.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Anaconda3_2022.10\Scripts\conda-script.py", line 12, in <module>
    sys.exit(main())
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\cli\main.py", line 128, in main
    return conda_exception_handler(main, *args, **kwargs)
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\exception_handler.py", line 388, in conda_exception_handler
    return_value = exception_handler(func, *args, **kwargs)
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\exception_handler.py", line 20, in __call__
    return self.handle_exception(exc_val, exc_tb)
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\exception_handler.py", line 51, in handle_exception
    from .exceptions import (
  File "D:\Anaconda3_2022.10\lib\site-packages\conda\exceptions.py", line 16, in <module>
    from requests.exceptions import JSONDecodeError
ImportError: cannot import name 'JSONDecodeError' from 'requests.exceptions' (D:\Anaconda3_2022.10\lib\site-packages\requests\exceptions.py)

解决方案

你遇到的错误是因为conda在尝试导入requests.exceptions模块中的JSONDecodeError类时失败了。这可能是因为你的requests库版本与conda期望的版本不兼容,或者requests库可能已损坏。

解决这个问题,你可以尝试以下几个步骤:

  1. 更新requests:尽管你可能无法直接通过conda来执行这一操作,因为错误看起来影响了conda的正常运行,但你可以尝试使用pip来更新requests库。打开命令提示符或终端,然后输入以下命令:

    pip install --upgrade requests
    
  2. 修复Anaconda环境:如果requests库的更新不能解决问题,可能需要修复你的Anaconda安装。你可以下载并运行Anaconda的最新安装器,它通常提供一个修复选项。

  3. 重装Anaconda:如果上述步骤都不能解决问题,可能需要卸载然后重新安装Anaconda。确保在卸载过程中删除所有相关的环境和配置文件,以避免潜在的版本冲突或残留文件影响新安装。

  4. 手动修复:如果你熟悉Python和Anaconda的工作原理,可以尝试检查D:\Anaconda3_2022.10\lib\site-packages\requests\exceptions.py文件,确认JSONDecodeError是否存在。如果不存在,可能需要手动修复这个文件,或者查找相关的requests版本来替换当前损坏或不兼容的版本。

转载请注明出处或者链接地址:https://www.qianduange.cn//article/19133.html
标签
评论
发布的文章

在C#中使用JSON

2024-11-04 10:11:05

JSON串

2024-11-04 10:11:57

JSON教程(非常详细)

2024-05-08 10:05:36

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!