iter_bytes raise ValueError when response body is empty #1819
Answered
by
tomchristie
heroesm
asked this question in
Potential Issue
-
Code to reproduce:import httpx
import respx
from httpx import Response
@respx.mock
def test_example():
respx.get("https://example.org/").mock(return_value=Response(200))
response = httpx.get("https://example.org/")
assert response.status_code == 200
assert response.text == ''
for chunk in response.iter_bytes():
print(chunk) Expcted result:No error Real result: File ".../httpx/_models.py", line 1491, in iter_bytes
for i in range(0, len(self._content), chunk_size):
ValueError: range() arg 3 must not be zero Related source codeLine 1491 in acb5e6a The async version Line 1589 in acb5e6a |
Beta Was this translation helpful? Give feedback.
Answered by
tomchristie
Aug 31, 2021
Replies: 1 comment 2 replies
-
Well caught, yup. I can also duplicate it without import httpx
transport = httpx.MockTransport(handler=lambda request: httpx.Response(204))
client = httpx.Client(transport=transport)
response = client.get('https://www.example.com/')
for chunk in response.iter_bytes():
print(chunk) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
tomchristie
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well caught, yup. I can also duplicate it without
respx
like so...