-
Notifications
You must be signed in to change notification settings - Fork 389
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
[BUG] HTTPX Binary upload data unsuported #656
Comments
Probably related: ktosiek/pytest-vcr#46 |
indeed it is |
The same thing happens when trying to record a cassette with httpx, where binary request data causes a import httpx
import requests
import vcr
requests_response = requests.post('http://example.com', data=b'\xff')
print(requests_response.status_code)
httpx_response = httpx.post('http://example.com', data=b'\xff')
print(httpx_response.status_code)
with vcr.use_cassette('requests.yaml'):
requests_response = requests.post('http://example.com', data=b'\xff')
print(requests_response.status_code)
with vcr.use_cassette('httpx.yaml'):
httpx_response = httpx.post('http://example.com', data=b'\xff')
print(httpx_response.status_code) Expected output:
Actual output:
This is with python 3.8.13, httpx==0.23.3, vcrpy==4.2.1. |
Can we use |
I still get the same error if i upload a file via httpx in a test with vcrpy.
|
Ok, my issue is fixed by this PR. |
This isssue should not be closed - PR #820 was not accepted, so the problem still occurs - it's not possible to use |
I worked around this problem in my own project by applying this monkey-patch, using code from #820: from vcr.request import Request as VcrRequest
from vcr.stubs import httpx_stubs
def _make_vcr_request(httpx_request, **kwargs):
try:
body = httpx_request.read().decode("utf-8")
except UnicodeDecodeError:
body = httpx_request.read().decode("ISO-8859-1").encode("utf-8")
uri = str(httpx_request.url)
headers = dict(httpx_request.headers)
return VcrRequest(httpx_request.method, uri, body, headers)
httpx_stubs._make_vcr_request = _make_vcr_request |
Thanks @simonw. I’ll reopen. Love your blog by the way! Thanks for using VCR. |
I am trying to migrate one library from requests to http and it seems httpx portion have some bugs
folowing casete cant be used with httpx
https://github.com/billdeitrick/pypco/blob/master/tests/cassettes/TestPublicRequestFunctions.test_upload_and_use_file.yaml
because it tries to decode the binary string (that is nonsense)
The text was updated successfully, but these errors were encountered: