Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'HTTPResponse' object has no attribute 'strict' #7936

Closed
4 tasks done
aakashrshah opened this issue May 16, 2023 · 38 comments
Closed
4 tasks done

'HTTPResponse' object has no attribute 'strict' #7936

aakashrshah opened this issue May 16, 2023 · 38 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@aakashrshah
Copy link

  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue


  AttributeError

  'HTTPResponse' object has no attribute 'strict'

  at ~/Library/Caches/pypoetry/virtualenvs/rubber-duck-py3.10/lib/python3.10/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│ 

I am not able to install or add packages and blocked significantly. I do not see this issue on internet. Am i using a wrong python version? this is the latest version of poetry , shall i revert?

@aakashrshah aakashrshah added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels May 16, 2023
@dimbleby
Copy link
Contributor

dimbleby commented May 16, 2023

this is psf/cachecontrol#292

however since poetry requirements do not allow urllib3 2.0, this shows that you, or whatever you used to install poetry, have upgraded something that you should not have done

please close

@dimbleby
Copy link
Contributor

PS I do not know why you write here "I do not see this issue on internet." when, as I now see, you have already commented on that other issue

@Secrus
Copy link
Member

Secrus commented May 17, 2023

Poetry has urllib3 pinned below 2.0, so you had to mess something up on your end (for example by installing your project and poetry into the same environment). In any case, this is not Poetry's fault.

@Secrus Secrus closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2023
@josumoreno-BP
Copy link

Can be the case that you are still using poetry < 1.2; in that case you will need to pin urllib to < 2 because it was a dev dependency as you can see here.

@aakashrshah
Copy link
Author

Good by me if we want to close it. Currently I removed the line with strict in cache control.

I tried it on python 3.10, 3.11 with latest poetry and latest pip.

I don’t know what did I mess up on my end.

Thanks though.

@aakashrshah
Copy link
Author

Can be the case that you are still using poetry < 1.2; in that case you will need to pin urllib to < 2 because it was a dev dependency as you can see here.

I surely confirm I am using latest version 1.4.2 in and out(global) of my virtual environment.

@chanwutk
Copy link

@aakashrshah I am having the same issue (this issue started to happen a couple days ago).
Would you mind if I ask you how did you "removed the line with strict in cache control", please?

@FachengG
Copy link

FachengG commented May 18, 2023

@chanwutk
Here is a solution for anyone faced similar problem:
use None to replace response.strict.

Not sure about side-effect, but it will work again.

@aakashrshah
Copy link
Author

@aakashrshah I am having the same issue (this issue started to happen a couple days ago).
Would you mind if I ask you how did you "removed the line with strict in cache control", please?

Hi @chanwutk

I deleted line 54
python3.10/site-packages/cachecontrol/serialize.py:54

@chanwutk
Copy link

Thank you!!

dragon-dxw added a commit to nationalarchives/ds-caselaw-pdf-conversion that referenced this issue May 18, 2023
There was a `'HTTPResponse' object has no attribute 'strict'` error
when building poetry inside the docker container;
python-poetry/poetry#7936
suggests it is an issue with poetry < 1.2 and not pinning urllib
to < 3.
kiran94 added a commit to kiran94/prfiesta that referenced this issue May 20, 2023
* chore(deps): add analysis dependencies

* feat(analysis): add pull request list view

* feat(analysis): implemented state distribution

* feat(analysis): implemented overall timeline distribution

* feat(analysis): implemented author association distribution

* feat(analysis): implemented conventional commit breakdown

* chore(deps): consolidated

* feat(analysis): implemented reaction distribution

* docs(sample): add plot and view samples

* chore(poetry): update lock

* chore(precommit): removed eof fixer

* chore(notebooks): moved view pull requests

* chore(verify): add papermill and jupyter verification scripts

* chore(notebooks): refresh

* chore(ci): verify notebooks

* chore(ci): build project

* chore(pyproject): comment out readme for now

* chore(ci): run poetry shell

* fix(ci): ensure poetry run is used for validate notebooks

* fix(ci): update validate notebooks

* chore(verbose): disable validation

* chore(ci): add amend

* fix(poetry): pin urllib below version 2

python-poetry/poetry#7936
https://github.com/kiran94/prfiesta/actions/runs/5031995017/jobs/9025385196#step:11:26

* chore(ci): restrict verify notebooks to linux

* chore(notebooks): refresh

* chore(notebooks): remove echo

* style(analysis): trailing whitespace
@lucafulgenzi
Copy link

System config:

  • Python: 3.11.3
  • Poetry: 1.4.2

Working with urllib3==1.26.9 installed globally

@trigremm
Copy link

trigremm commented May 22, 2023

poetry add "urllib3<=2.0" solved the topic issue for my projects

@Yanqiao4396
Copy link

poetry add "urllib3<=2.0" solved the topic issue for my projects

Didn't work on mine, unfortunately

@trigremm
Copy link

poetry add "urllib3<=2.0" solved the topic issue for my projects

Didn't work on mine, unfortunately

Have you tried to check urllib3 version and if in case of >=2.0 downgrade it via pip and repeat ?

@trigremm
Copy link

trigremm commented May 23, 2023

poetry add "urllib3<=2.0" solved the topic issue for my projects

Didn't work on mine, unfortunately

Have you tried to check urllib3 version and if in case of >=2.0 downgrade it via pip and repeat ?

urllib3 Remove strict parameter 2064
urllib3/urllib3#2064

IagoAbal added a commit to semgrep/semgrep-action that referenced this issue May 24, 2023
IagoAbal added a commit to semgrep/semgrep-action that referenced this issue May 24, 2023
IagoAbal added a commit to semgrep/semgrep-action that referenced this issue May 24, 2023
IagoAbal added a commit to semgrep/semgrep-action that referenced this issue May 24, 2023
IagoAbal added a commit to semgrep/semgrep-action that referenced this issue May 24, 2023
IagoAbal added a commit to semgrep/semgrep-action that referenced this issue May 24, 2023
Started to get errors in CI during the installation of dependencies,
apparently due to incompatibilities between Poetry and urllib3 >=2.0.
No idea why urllib3 >=2.0 only started to get installed now, perhaps
something changed in GHA's side.

Poetry 1.2.0 already requires urllib3 <2.0 thus solving the problem.

See python-poetry/poetry#7936
@vetsin
Copy link

vetsin commented May 24, 2023

Had this issue seemingly because i've installed my package into the same pyenv environment poetry exists on --

had to manually add the del line in ~/.pyenv/versions/3.11.3/lib/python3.11/site-packages/cachecontrol/serialize.py's prepare_response method as follows:

        del cached["response"]["strict"]
        return HTTPResponse(body=body, preload_content=False, **cached["response"])

From there I was able to poetry update

@Yanqiao4396
Copy link

Yanqiao4396 commented May 25, 2023

poetry add "urllib3<=2.0" solved the topic issue for my projects

Didn't work on mine, unfortunately

Have you tried to check urllib3 version and if in case of >=2.0 downgrade it via pip and repeat ?

urllib3 Remove strict parameter 2064 urllib3/urllib3#2064

Thank you for the reply, my issue is solved by upgrading my Poetry version to 1.4.2 (versions below that may still work but I didn't try) or above (it was 1.1.13 before). I guess my issue comes from Requests dependency that Poetry itself uses

@paultiplady
Copy link

Maybe context-specific, but I fixed this by using pyenv to split poetry into a separate venv.

pyenv local myproject 3.7.9 sets pyenv to look for executables first in myproject (the local project-specific venv) followed by 3.7.9 (the global python version where I've installed poetry). You could also create a completely separate venv just for poetry.

Another approach might be to use pipx to run poetry, since it handles isolating the executable in its own venv.

@vcidst
Copy link

vcidst commented May 26, 2023

Downgrading requests worked for me, pip install requests==2.28

Is this error related to psf/cachecontrol#301 which was merged yesterday?
I was using poetry==1.1.13 and the docker builds started failing since poetry installs the latest version of requests package.

@amites
Copy link

amites commented Jun 2, 2023

add this reference which provides some guidance for how to migrate from 1.x to 2.x for urllib3
https://urllib3.readthedocs.io/en/latest/v2-migration-guide.html

if you pin versions for

urllib3==1.26.16
requests==2.29.0

everything continues to work

@n-splv
Copy link

n-splv commented Jun 15, 2023

Turns out, not all responses come with "strict" key. I had to add the following in prepare_response in site-packages/cachecontrol/serialize.py:

    if cached["response"].get("strict") is not None:
      del cached["response"]["strict"]

@diegoquintanav
Copy link

diegoquintanav commented Jul 13, 2023

In my case, I started getting this error after something I did with pipx (can't tell really what happened). Running pipx install poetry --force fixed poetry for me.

@XChikuX
Copy link

XChikuX commented Jul 14, 2023

Just always pin these dependencies for poetry and you should be good.

[tool.poetry.dependencies]
python = "^3.10"
charset-normalizer = "^3.1.0"  # Needed cause of a bug in poetry
urllib3 = "^1.26.16"  # Needed cause of a bug in poetry

Just downgrade urllib3 with pip in case you broke poetry.

@jeromegit
Copy link

Running this worked for me:
pip install -U requests==2.28.2 urllib3==1.26.15
(using poetry 1.4)

@tew9
Copy link

tew9 commented Aug 10, 2023

I had the same issue, and I fix it by deleting the terminal I was running it from and rerun it in another terminal.
It was a virtual environment issue for me.
Issue: I was debugging using a terminal which is running poetry virtual environment.
Fix: I deleted the terminal and create the new one that was on base environment and everything works fine.

hope that helps

@sir-kokabi
Copy link

I've deleted all poetry virtual environments and created a new virtual environment again, and the problem was resolved.
windows 11.

@bramses
Copy link

bramses commented Jan 4, 2024

For me, I had moved my folder with poetry into a subfolder later on and for some reason that broke everything.

  1. poetry shell was in ~/folder_a
  2. i moved folder_a into ~/new_parent_folder/folder_a
  3. this broke poetry add, poetry install etc

still not sure why. but when i moved it back to ~, it was fine again.

@hungiito
Copy link

I had the same problem when installing poetry in a virtual environment. I found that when running poetry install in a virtual environment, poetry still use outdated urllib3 and requests installed in the machine. So I tried to upgrade urllib3 and requests (outside of virtual environment) and it works.

In short

deactivate # deactivate virtual env (if activated)
pip3 install --upgrade pip
pip3 install --upgrade urllib3 requests

@Telofy
Copy link

Telofy commented Feb 6, 2024

I was about to fork Poetry and create a PR that adds the urllib3 = "^1.26.16" dependency to Poetry's pyproject.toml, but something tells me there's probably some recondite reason for the omission of the dependency? Or has just no one gotten around to adding it?

@Secrus
Copy link
Member

Secrus commented Feb 6, 2024

I was about to fork Poetry and create a PR that adds the urllib3 = "^1.26.16" dependency to Poetry's pyproject.toml, but something tells me there's probably some recondite reason for the omission of the dependency? Or has just no one gotten around to adding it?

Yes, there reason is that this bug is not present in Poetry anymore. This is only a case for non-standard installation which are discouraged.

@Telofy
Copy link

Telofy commented Feb 6, 2024

Oh, thx! There must've been something nonstandard about my environment because I used mamba/conda for another project. But now I'm running into #8679 instead of this one. ^.^

@LaoshuBaby
Copy link

To above all, why not check pip install poetry urllib3 requests --upgrade? I meet with this issue today when I run "poetry install", I can't downgrade urllib3 because other part of project lock the dependency version, and only upgrade those 2 like hungiito wrote won't work.

That's because I forgot to upgrade the most important poetry-1.4.1, and that version require urllib3<2.0.0,>=1.26.0

But now the latest version of poetry is 1.8.1, and everythings work fluently, don't need to manually edit any link in site-packages. Now what about try to upgrade those 3 package all?

@hungiito
Copy link

hungiito commented Mar 2, 2024

@LaoshuBaby Have you tried upgrading urllib3 and requests outside of Poetry's virtual environment? In my case, I installed Poetry in a venv folder and noticed that Poetry uses the urllib3 in root environment rather than in venv directory

@LaoshuBaby
Copy link

@LaoshuBaby Have you tried upgrading urllib3 and requests outside of Poetry's virtual environment? In my case, I installed Poetry in a venv folder and noticed that Poetry uses the urllib3 in root environment rather than in venv directory

I did not specify a venv environment

@hungiito
Copy link

hungiito commented Mar 3, 2024

@LaoshuBaby Have you tried upgrading urllib3 and requests outside of Poetry's virtual environment? In my case, I installed Poetry in a venv folder and noticed that Poetry uses the urllib3 in root environment rather than in venv directory

I did not specify a venv environment

Can you try upgrading both pip and poetry

pip install --upgrade pip poetry

@LaoshuBaby
Copy link

@hungiito

To above all, why not check pip install poetry urllib3 requests --upgrade?
-- In my reply #7936 (comment)

I execute this command and upgrade everything to the latest, which can solve the problem originally raised by this issue.

Can you try upgrading both pip and poetry

You can do it without upgrading pip, but it will not cause problems if you upgrade it according to my test.

(In short, now my pip, requests, urllib3, and poetry are all up to date.)

That's why I recommend you upgrade(if you can) them.

@ChrCoello
Copy link

ChrCoello commented Mar 5, 2024

As @jeromegit wrote earlier, this is surely due to using Poetry 1.4.
Same error arose when we had to use conda (Azure ML Compute) as virtual environment manager (always try to avoid conda at any cost...). Then when one installs poetry on a freshly created conda environment using conda

conda install poetry

Poetry 1.4 is installed, by the same time downgrading urlib3 and requests.
Using pip to install Poetry solved the "issue", installing latest Poetry 1.8 without any downgrade

pip install poetry

Copy link

github-actions bot commented Apr 5, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests