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

Doesn't work with httpx #46

Open
rkhwaja opened this issue Oct 5, 2021 · 1 comment
Open

Doesn't work with httpx #46

rkhwaja opened this issue Oct 5, 2021 · 1 comment

Comments

@rkhwaja
Copy link

rkhwaja commented Oct 5, 2021

I'm not sure whether this package is expected to work with httpx but I'm getting the following error when recording a new cassette with decode_compressed_response=True:

>           new_body = decompress_body(response["body"]["string"], encoding)
E           KeyError: 'body'
rkhwaja added a commit to rkhwaja/wccls that referenced this issue Oct 5, 2021
rkhwaja added a commit to rkhwaja/wccls that referenced this issue Oct 21, 2021
rkhwaja added a commit to rkhwaja/wccls that referenced this issue Dec 24, 2021
@Sinkler
Copy link

Sinkler commented Aug 31, 2022

Monkey patch:

from vcr.stubs import httpx_stubs

def _transform_headers(httpx_response):
    out = {}
    for key, var in httpx_response.headers.raw:
        decoded_key = key.decode('utf-8')
        decoded_var = var.decode('utf-8')
        if decoded_key.lower() == 'content-encoding' and decoded_var in ('gzip', 'deflate'):
            continue
        out.setdefault(decoded_key, [])
        out[decoded_key].append(decoded_var)
    return out


httpx_stubs._transform_headers = _transform_headers

See: kevin1024/vcrpy#591 and kevin1024/vcrpy#649

adamantike added a commit to rommapp/romm that referenced this issue Jul 24, 2024
`pytest-vcr` [1] is no longer maintained (last commit was in 2020), and
`VCR.py` recommends [2] `pytest-recording` instead.

Also, `pytest-vcr` does not correctly support `httpx` [3].

This change also removes unused cassettes.

[1] https://github.com/ktosiek/pytest-vcr
[2] https://vcrpy.readthedocs.io/en/latest/usage.html#pytest-integration
[3] ktosiek/pytest-vcr#46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants