Open zepaz opened 5 months ago
Adding a comment here in the hopes it will help anyone else who ends up here. We had a bug in our code, we were using responses to return a 204 but we had content in the body.
import json
import responses
import requests
def call_me(_request):
headers = {"Content-Type": "application/json"}
body = {}
# A bunch of logic to populate the body....
if not body:
# Bug is here. The body should be `None` not an empty object
return 204, headers, json.dumps(body)
else:
return 200, headers, json.dumps(body)
@responses.activate
def test_post_204():
responses.add_callback(responses.POST, "https://example.com", call_me)
resp = requests.post("https://example.com")
assert resp.status_code == 204
And it was producing the same ChunkedEncodingError
so at first we thought it was the same root cause as this issue.
It had been working for years, but when we upgraded requests, urllib3 got upgraded to 2.2.3 and that broke all our mocks.
Pinning urllib3 = "^1.26.20"
is the work around for us while we find and fix all the issues in our code.
that is not a bug in responses but a changed functionality in the urllib3
in 2.0
see comment here: https://github.com/getsentry/responses/issues/635#issuecomment-1538862145
Describe the bug
When mocking requests.head() a
ChunkedEncodingError
is raised if you send something in the header but omitcontent-length
in said header.Additional context
No response
Version of
responses
0.25.2
Steps to Reproduce
run
pytest
Expected Result
I would expect the test to succeed.
Actual Result
the test raises an
ChunkedEncodingError