如何修复Poetry报错‘HTTPResponse’对象没有‘strict’属性?
解决Poetry 1.1.14执行
poetry add isort@5.11.5时的AttributeError错误 问题场景
在Python 3.8环境下用Poetry 1.1.14执行命令 poetry add isort@5.11.5,触发以下错误:
Updating dependencies Resolving dependencies... (0.4s) AttributeError 'HTTPResponse' object has no attribute 'strict' at ~/Library/Application Support/pypoetry/venv/lib/python3.8/site-packages/cachecontrol/serialize.py:54 in dumps 50│ ), 51│ u"status": response.status, 52│ u"version": response.version, 53│ u"reason": text_type(response.reason), → 54│ u"strict": response.strict, 55│ u"decode_content": response.decode_content, 56│ } 57│ } 58│
解决办法
方案1:升级Poetry(推荐)
旧版Poetry(1.1.x系列)依赖的cachecontrol库和新版urllib3存在兼容性问题,升级Poetry到最新稳定版能彻底解决这个问题。执行以下命令完成升级:
curl -sSL https://install.python-poetry.org | python3 -
Windows用户可按照Poetry官方提供的升级方式操作。
方案2:临时降级urllib3(不升级Poetry时用)
如果暂时不想升级Poetry,可通过降级Poetry虚拟环境里的urllib3到兼容版本来修复:
- 进入Poetry的虚拟环境,路径对应报错信息里的
~/Library/Application Support/pypoetry/venv(MacOS),Windows路径为%APPDATA%\pypoetry\venv - 执行命令降级urllib3:
pip install urllib3==1.26.18 - 重新执行
poetry add isort@5.11.5即可。
内容的提问来源于stack exchange,提问作者sshevlyagin
相关产品推荐
相关产品推荐

