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

AttributeError: 'VCRHTTPResponse' object has no attribute 'json' #774

Open
gschnellOnera opened this issue Oct 2, 2023 · 2 comments
Open

Comments

@gschnellOnera
Copy link

I use pytest-recording, to mimic my http requests for testing. When switching to urllib3 to run the queries I encounter the following exception. AttributeError: 'VCRHTTPResponse' object has no attribute 'json'

from urllib3 import PoolManager, make_headers

HTTP_PoolManager = PoolManager()
HTTP_HEADER_AUTH = make_headers(basic_auth='user:password')
req = HTTP_PoolManager.request('GET', url, headers=HTTP_HEADER_AUTH)
if (req.status != 200):
    if req.headers['content-type'].split(';')[0] == "application/json":
        return req.json()
#error managment
retrun None

Versions:
python 3.8.10
pytest-recording: 0.13.0
vcrpy: 5.1.0
urllib3: 2.0.4

Workaround:

from urllib3 import PoolManager, make_headers
import json

HTTP_PoolManager = PoolManager()
HTTP_HEADER_AUTH = make_headers(basic_auth='user:password')
req = HTTP_PoolManager.request('GET', url, headers=HTTP_HEADER_AUTH)
if (req.status != 200):
    if req.headers['content-type'].split(';')[0] == "application/json":
        return json.loads(req.data)
#error managment
retrun None
@dmelo
Copy link

dmelo commented Nov 2, 2023

I might be wrong, but AFAIK, your issue will be solved after vcrpy releases a new version that supports urllib3 v2 -> #707

@hartwork
Copy link
Collaborator

hartwork commented Dec 8, 2023

@gschnellOnera the snippet you shared requires additional work to run in isolation. Could you turn it into a snippet reproducer that can be in isolation easily? Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants