-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
requests.head raises ChunkedEncodingError if header without content-length is sent #721
Comments
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 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 |
that is not a bug in responses but a changed functionality in the see comment here: #635 (comment) |
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
The text was updated successfully, but these errors were encountered: